Fix: avoid mutating device.name in _get_common_name#1300
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 (1)
📜 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 (3)📚 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:
🔇 Additional comments (2)
📝 WalkthroughWalkthroughThis change modifies Sequence Diagram(s)Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ 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 |
Commit Message Format FailureHello @k-sumayya, The CI failed because the commit message does not follow the required format. Please ensure your commit messages adhere to the following structure:
Here is an example of a correctly formatted commit message: |
This fixes an issue where device.name was modified in-place, which could cause unexpected behavior due to Django ORM caching. Fixes openwisp#1300
c392985 to
4510266
Compare
This fixes an issue where device.name was modified in-place, which could cause unexpected behavior due to Django ORM caching. Fixes openwisp#1300
4510266 to
46acb5f
Compare
|
Thank you for the review! Please let me know if anything else is needed from my side. |
nemesifier
left a comment
There was a problem hiding this comment.
Good catch @k-sumayya, this is a correct and worthwhile fix. The old code did d.name = d.name[:end], mutating the in-memory device instance as a side effect of generating a VPN common name. Because that object can be reused and potentially saved later in the same request, this could silently truncate and persist the device's actual name. Switching to a local name variable removes the side effect while keeping identical output.
One thing before merge:
- Please add a regression test asserting that after
_get_common_name()runs,device.nameis unchanged (and that the generated common name is still correct, including the{mac_address}-{name}collapse-to-{mac_address}branch). This is exactly the kind of side-effect bug that silently comes back without a test pinning it.
Correct fix, just add the test and it is ready.
Fix: Avoid in-place mutation of device.name in _get_common_name
This PR fixes an issue where
_get_common_namewas mutatingdevice.namedirectly, causing unintended side effects due to Django ORM caching.Changes:
device.namenameto safely handle truncationResult:
device.nameunchangedCloses #1296