Fix: avoid mutating device.name in _get_common_name
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
nameto safely handle truncation - Ensured formatting uses the derived value instead of modifying the original object
Result:
- Prevents silent data corruption
- Keeps original
device.nameunchanged - Aligns with expected behavior
Closes #1296
[!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_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto 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.pyopenwisp_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.namemutation 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.
Comment @coderabbitai help to get the list of available commands.
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 titleor[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
coverage: 98.685% (+0.03%) from 98.658% when pulling 46acb5ff4b1651baf18be9ab2f97d58deb4c8b2e on k-sumayya:fix-common-name-bug into 45b24b65386d6e28dcaf2b235ee161311510045c on openwisp:master.
Thank you for the review! Please let me know if anything else is needed from my side.
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! ๐
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! ๐ค
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.
The CI is failing due to transient infrastructure issues (not related to your code). I have restarted the failed jobs automatically (1/3).
The CI is failing due to transient infrastructure issues (not related to your code). I have restarted the failed jobs automatically (2/3).
The CI is failing due to transient infrastructure issues (not related to your code). I have restarted the failed jobs automatically (3/3).
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.
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
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!
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?
@coderabbitai summary
Summary regeneration triggered.โ
Action performed