Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openwisp_controller/config/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def _update_config(self, device, config_data):
if config_templates != old_templates:
with transaction.atomic():
vpn_list = config.templates.filter(type="vpn").values_list("vpn")
if vpn_list:
config.vpnclient_set.exclude(vpn__in=vpn_list).delete()
for client in config.vpnclient_set.exclude(vpn__in=vpn_list).iterator():
client.delete()
config.templates.set(config_templates, clear=True)
config.save()
except ValidationError as error:
Expand Down
8 changes: 5 additions & 3 deletions openwisp_controller/config/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def manage_vpn_clients(cls, action, instance, pk_set, **kwargs):
if instance.is_deactivating_or_deactivated():
# If the device is deactivated or in the process of deactivating, then
# delete all vpn clients and return.
instance.vpnclient_set.all().delete()
for client in instance.vpnclient_set.all().iterator():
client.delete()
return

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

if action == "post_add":
for template in templates.filter(type="vpn"):
Expand Down
Loading