Commit 2e5180c
committed
[fix] Ensure VpnClient.post_delete fires on VPN template removal openwisp#1221
Replaced QuerySet.delete() with per-instance deletion in all three
locations where VpnClient objects are bulk-deleted so that post_delete
signals fire for every instance, ensuring:
- VPN peer cache is invalidated on the affected VPN server
- Client certificates are revoked (OpenVPN, auto_cert=True)
- IP addresses are released (Wireguard)
Also fixed the serializers.py cleanup logic: vpn_list was built from
the old templates so .exclude(vpn__in=vpn_list) never matched the
client being removed. Now uses new_vpn_ids from config_templates (the
incoming new set) so PATCH with an empty templates list also works.
Added select_related("vpn", "cert", "ip") to all deletion querysets
to avoid N+1 queries triggered by the post_delete signal handler.
Wrapped deletion loops in transaction.atomic() to prevent partial
deletions on failure.
Fixes openwisp#12211 parent d4d013f commit 2e5180c
2 files changed
+23
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
204 | | - | |
205 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
206 | 212 | | |
207 | 213 | | |
208 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
341 | | - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
342 | 346 | | |
343 | 347 | | |
344 | 348 | | |
| |||
370 | 374 | | |
371 | 375 | | |
372 | 376 | | |
373 | | - | |
374 | | - | |
375 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
376 | 386 | | |
377 | 387 | | |
378 | 388 | | |
| |||
0 commit comments