openwisp-controller icon indicating copy to clipboard operation
openwisp-controller copied to clipboard

Fix: avoid mutating device.name in _get_common_name

Open k-sumayya opened this issue 8 months ago โ€ข 13 comments

Fix: Avoid in-place mutation of device.name in _get_common_name

This PR fixes an issue where _get_common_name was mutating device.name directly, causing unintended side effects due to Django ORM caching.

Changes:

  • Removed in-place mutation of device.name
  • Introduced a local variable name to safely handle truncation
  • Ensured formatting uses the derived value instead of modifying the original object

Result:

  • Prevents silent data corruption
  • Keeps original device.name unchanged
  • Aligns with expected behavior

Closes #1296

k-sumayya avatar Mar 19 '26 07:03 k-sumayya

Review Change Stack

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] โ–ถ๏ธ Resume reviews
  • [ ] ๐Ÿ” Trigger review
โ„น๏ธ Recent review info
โš™๏ธ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ddf01a15-911b-4423-a627-9e950731e296

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between e0ee749e22c7fa1445d8ce9ad1d289c08ce74feb and 715c852c92c24ddc71aaaa312a9929c9c85ca50a.

๐Ÿ“’ Files selected for processing (2)
  • openwisp_controller/config/base/vpn.py
  • openwisp_controller/config/tests/test_vpn.py

๐Ÿ“ Walkthrough

Walkthrough

AbstractVpnClient._get_common_name() now truncates the device name locally, uses it for common-name formatting, and leaves d.name unchanged. The long-name test verifies this non-mutating behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • openwisp/openwisp-controller#1284 โ€” Addresses the same in-place device.name mutation in _get_common_name().
๐Ÿšฅ Pre-merge checks | โœ… 5
โœ… Passed checks (5 passed)
Check name Status Explanation
Title check โœ… Passed Title clearly identifies the fix and matches the issue's core problem - preventing mutation of device.name in _get_common_name.
Description check โœ… Passed Description covers the problem, changes made, and results, though it lacks a screenshot section which is non-critical.
Linked Issues check โœ… Passed Changes fully satisfy issue #1296 requirements: removed in-place mutation, introduced local variable for truncation, preserved original device.name, and prevent side effects.
Out of Scope Changes check โœ… Passed All changes are directly related to fixing the device.name mutation issue in _get_common_name() and corresponding test updates, with no out-of-scope modifications.
Bug Fixes โœ… Passed _get_common_name truncates into local name and formats CN without writing back to d.name; test_auto_create_cert_with_long_device_name asserts d.name unchanged and CN base (excluding random suffix...

โœ๏ธ Tip: You can configure your own custom pre-merge checks in the settings.

โœจ Finishing Touches
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Mar 19 '26 07:03 coderabbitai[bot]

Commit Message Format Failure

Hello @k-sumayya, (Analysis for commit c392985)

The CI failed because the commit message does not follow the required format. Please ensure your commit messages adhere to the following structure:

  • Header: [prefix] Capitalized title or [prefix] Capitalized title #<issue>
  • Body: A blank line after the header, followed by a detailed description.
  • Footer: A closing keyword and issue number (e.g., Fixes #<issue>).

Here is an example of a correctly formatted commit message:

[fix] Update user authentication logic #123

This commit addresses an issue where users were unable to log in due to an incorrect password hashing algorithm. The hashing algorithm has been updated to bcrypt, and all existing user passwords have been rehashed.

Fixes #123

openwisp-companion avatar Mar 19 '26 08:03 openwisp-companion

Coverage Status

coverage: 98.685% (+0.03%) from 98.658% when pulling 46acb5ff4b1651baf18be9ab2f97d58deb4c8b2e on k-sumayya:fix-common-name-bug into 45b24b65386d6e28dcaf2b235ee161311510045c on openwisp:master.

coveralls avatar Mar 19 '26 09:03 coveralls

Thank you for the review! Please let me know if anything else is needed from my side.

k-sumayya avatar Mar 19 '26 09:03 k-sumayya

Hi @k-sumayya ๐Ÿ‘‹,

This is a friendly reminder that this pull request has had no activity for 8 days since changes were requested.

We'd love to see this contribution merged! Please take a moment to:

  • Address the review feedback
  • Push your changes
  • Let us know if you have any questions or need clarification

If you're busy or need more time, no worries! Just leave a comment to let us know you're still working on it.

Note: within 6 more days, the linked issue will be unassigned to allow other contributors to work on it.

Thank you for your contribution! ๐Ÿ™

openwisp-companion avatar Jun 07 '26 04:06 openwisp-companion

Hi @k-sumayya ๐Ÿ‘‹,

This pull request has been marked as stale due to 14 days of inactivity after changes were requested.

As a result, any linked issues are being unassigned from you so other contributors can pick them up.

However, you can still continue working on this PR! If you push new commits or respond to the review feedback:

  • The issue will be reassigned to you
  • Your contribution is still very welcome

If you need more time or have questions about the requested changes, please let us know. We're happy to help! ๐Ÿค

openwisp-companion avatar Jun 13 '26 04:06 openwisp-companion

Dependency Conflict During Package Installation

Hello @k-sumayya, (Analysis for commit 520e8a0)

There is a dependency conflict between openwisp-controller and openwisp-ipam packages during the installation process.

Failure:

The CI failed because openwisp-controller==1.3a0 depends on django-reversion~=6.0.0, while openwisp-ipam==1.3a0 depends on django-reversion~=6.2.0. Pip cannot resolve these conflicting version requirements.

To Fix:

Update the version specifier for django-reversion in the requirements-test.txt file to a compatible version that satisfies both dependencies. For example, you could try django-reversion~=6.2.0 or a more relaxed range if appropriate.

openwisp-companion avatar Jun 13 '26 08:06 openwisp-companion

The CI is failing due to transient infrastructure issues (not related to your code). I have restarted the failed jobs automatically (1/3).

openwisp-companion avatar Jun 13 '26 09:06 openwisp-companion

The CI is failing due to transient infrastructure issues (not related to your code). I have restarted the failed jobs automatically (2/3).

openwisp-companion avatar Jun 13 '26 09:06 openwisp-companion

The CI is failing due to transient infrastructure issues (not related to your code). I have restarted the failed jobs automatically (3/3).

openwisp-companion avatar Jun 13 '26 09:06 openwisp-companion

Test Failures in Selenium Tests

Hello @k-sumayya, (Analysis for commit 715c852)

The CI build failed due to a test error in TestDevice.test_restoring_deleted_device.

Failure: A TypeError: 'NoneType' object is not iterable occurred in the test test_restoring_deleted_device within the TestDevice class. This indicates that a function expected to return an iterable (like a list or tuple) returned None instead.

Location: The error originates from the line for error in self.get_browser_logs(): in the test file openwisp_controller/tests/test_selenium.py. This suggests that self.get_browser_logs() returned None.

Fix: The get_browser_logs method in the TestDevice class likely needs to be reviewed to ensure it always returns an iterable, even if there are no logs. It's possible that in certain test conditions, it's returning None when it should return an empty list.

Additionally, several other Selenium tests are reported as slow, which is a separate issue that might need attention after the primary failure is resolved.

openwisp-companion avatar Jun 13 '26 10:06 openwisp-companion

Added the requested regression test to ensure device.name remains unchanged after _get_common_name() runs. The remaining CI failure appears to be in the unrelated Selenium test TestDevice.test_restoring_deleted_device

k-sumayya avatar Jun 13 '26 13:06 k-sumayya

Thanks for following up, @k-sumayya! ๐Ÿ™Œ The stale status has been removed and the linked issue(s) have been reassigned to you. Looking forward to your updates!

openwisp-companion avatar Jun 13 '26 13:06 openwisp-companion

Hi @k-sumayya, nice work on the PR! Its minimal and solves the issue correctly, could you please update the branch to the latest commit?

CodingWithSaksham avatar Jul 20 '26 06:07 CodingWithSaksham

@coderabbitai summary

CodingWithSaksham avatar Jul 20 '26 06:07 CodingWithSaksham

โœ… Action performed

Summary regeneration triggered.

coderabbitai[bot] avatar Jul 20 '26 06:07 coderabbitai[bot]