[fix] Ensure VpnClient.post_delete fires on template removal #1221 [backport 1.2]#1319
[fix] Ensure VpnClient.post_delete fires on template removal #1221 [backport 1.2]#1319mn-ram wants to merge 1 commit intoopenwisp:1.2from
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
…#1221 Backport of the fix from master to the 1.2.x branch. Replaced QuerySet.delete() with per-instance deletion so that post_delete signals fire for every VpnClient, ensuring: - VPN peer cache is invalidated - Client certificates are revoked (OpenVPN) - IP addresses are released (Wireguard) Also fixed serializers.py vpn_list logic: now uses new_vpn_ids from config_templates so PATCH with empty templates list also works correctly. Added select_related("vpn", "cert", "ip") to all deletion querysets to prevent N+1 queries. Wrapped loops in transaction.atomic(). Added regression tests for template removal, device deactivation, and multiple VPN clients. Fixes openwisp#1221
b170b18 to
edf4801
Compare
|
Closing this manual backport. The automated backport workflow will create the 1.2 backport PR automatically once #1277 is merged, provided the commit includes [backport 1.2] in the message. |
Backport of #1277 to the 1.2.x branch
This is a backport of the fix for issue #1221 targeting the
1.2maintenance branch.Problem
QuerySet.delete()performs a bulk delete bypassing per-instancepost_deletesignals. When VPN clients are deleted in bulk, theVpnClient.post_deletehandler does not fire, leaving:Solution
Replaced all three bulk
.delete()calls with per-instance deletion loops using.select_related("vpn", "cert", "ip").iterator()andtransaction.atomic().Also fixed the
serializers.pyvpn cleanup logic:vpn_listwas built from the old templates so.exclude(vpn__in=vpn_list)never matched the client being removed. Now usesnew_vpn_idsfromconfig_templates(the incoming new set).Files changed
config/base/config.py— two bulk deletes replaced (deactivation + template sync)config/api/serializers.py— bulk delete replaced + vpn_list logic fixedconfig/tests/test_vpn.py— three regression tests addedCHANGES.rst— changelog entry under 1.2.3 [unreleased]Fixes #1221
🤖 Generated with Claude Code