[fix] _get_common_name() must not mutate the device name in-place#1294
[fix] _get_common_name() must not mutate the device name in-place#1294mn-ram wants to merge 1 commit intoopenwisp:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
🧰 Additional context used📓 Path-based instructions (4)**/*.{js,ts,tsx,jsx,py,java,go,cs,rb,php,c,cpp,h,hpp}📄 CodeRabbit inference engine (Custom checks)
Files:
**/*.{js,ts,tsx,jsx,py,java,go,cs,rb,php,c,cpp,h,hpp,sql}📄 CodeRabbit inference engine (Custom checks)
Files:
**/*.{js,ts,tsx,jsx,py,java,go,cs,rb,php,c,cpp,h,hpp,sh,bash,sql}📄 CodeRabbit inference engine (Custom checks)
Files:
**/*.{py,html}📄 CodeRabbit inference engine (Custom checks)
Files:
🧠 Learnings (4)📚 Learning: 2026-01-15T15:05:49.557ZApplied to files:
📚 Learning: 2026-02-17T19:13:10.088ZApplied to files:
📚 Learning: 2026-01-15T15:07:17.354ZApplied to files:
📚 Learning: 2026-01-12T22:27:48.342ZApplied to files:
🔇 Additional comments (4)
📝 WalkthroughWalkthroughThe PR fixes a bug in AbstractVpn._get_common_name that previously mutated Device.name in-place. The implementation now copies the device name into a local variable, builds an explicit formatting context, applies truncation to the formatted common name, and avoids changing the in-memory Device object. Tests were added in two test files to assert that device.name is not mutated during VPN certificate provisioning for long and short names (note: the registration test appears duplicated in the test file). Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 Tip CodeRabbit can use your project's `ruff` configuration to improve the quality of Python code reviews.Add a Ruff configuration file to your project to customize how CodeRabbit runs |
CI Failures: Black, Commit Message, Test FailureHello @prakash-kalwaniya,
Specifically, the commit title needs to start with a capital letter after the
Please address the code style and commit message issues first, then re-run the CI to see if the test passes. If the test still fails, further investigation into the test logic might be needed. |
e010474 to
be3f41a
Compare
This comment was marked as spam.
This comment was marked as spam.
nemesifier
left a comment
There was a problem hiding this comment.
What issue is this solving? It seems like too much code for an issue that is not even listed in our issue list. Not a priority.
This comment was marked as spam.
This comment was marked as spam.
|
Unsolicited |
"""
[fix] Prevent silent device name corruption in _get_common_name()
Problem
AbstractVpnClient._get_common_name() (openwisp_controller/config/base/vpn.py) was truncating the device name for cert CN generation by writing directly back onto the model instance:
d.name = d.name[:end] # unintended in-place mutation
This is a silent data corruption bug. Because Django caches FK targets on model instances, self.config.device inside _get_common_name() is the exact same Python object as the device variable held
by DeviceRegisterView.post(). The mutation therefore escaped the method boundary, with two concrete downstream effects:
database—overwriting the operator-configured name permanently. No exception was raised, no log entry was written.
Trigger conditions (both required):
Why the existing test didn't catch this:
Fix
name = d.name[:end]# local variable — device never touchedcontext = {**d.__dict__, "name": name}# all device fields still accessiblecommon_name = cn_format.format(**context)[:55]Edge Cases Handled
Tests
openwisp_controller/config/tests/test_vpn.py
openwisp_controller/config/tests/test_controller.py
Real-World Impact
Notes for Reviewers
"""