Skip to content

Commit 6fc7dec

Browse files
committed
[fix] Ensure VpnClient post_delete signal fires on template removal #1221
Replaced bulk QuerySet.delete() with per-instance .delete() in three code paths so that VpnClient.post_delete signal is triggered, ensuring peer cache invalidation, certificate revocation and IP release. Closes #1221 Signed-off-by: prakash-kalwaniya <kalwaniyaprakash1@gmail.com>
1 parent d203490 commit 6fc7dec

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

openwisp_controller/config/api/serializers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ def _update_config(self, device, config_data):
202202
with transaction.atomic():
203203
vpn_list = config.templates.filter(type="vpn").values_list("vpn")
204204
if vpn_list:
205-
config.vpnclient_set.exclude(vpn__in=vpn_list).delete()
205+
for vpnclient in (
206+
config.vpnclient_set.exclude(
207+
vpn__in=vpn_list
208+
).iterator()
209+
):
210+
vpnclient.delete()
206211
config.templates.set(config_templates, clear=True)
207212
config.save()
208213
except ValidationError as error:

openwisp_controller/config/base/config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ def manage_vpn_clients(cls, action, instance, pk_set, **kwargs):
338338
if instance.is_deactivating_or_deactivated():
339339
# If the device is deactivated or in the process of deactivating, then
340340
# delete all vpn clients and return.
341-
instance.vpnclient_set.all().delete()
341+
for vpnclient in instance.vpnclient_set.all().iterator():
342+
vpnclient.delete()
342343
return
343344

344345
vpn_client_model = cls.vpn.through
@@ -370,9 +371,10 @@ def manage_vpn_clients(cls, action, instance, pk_set, **kwargs):
370371
# signal is triggered again—after all templates, including the required
371372
# ones, have been fully added. At that point, we can identify and
372373
# delete VpnClient objects not linked to the final template set.
373-
instance.vpnclient_set.exclude(
374+
for vpnclient in instance.vpnclient_set.exclude(
374375
template_id__in=instance.templates.values_list("id", flat=True)
375-
).delete()
376+
).iterator():
377+
vpnclient.delete()
376378

377379
if action == "post_add":
378380
for template in templates.filter(type="vpn"):

0 commit comments

Comments
 (0)