Skip to content

Commit 49c07f9

Browse files
committed
[fix] Invalidate DeviceGroup cache when Cert.organization is None
1 parent aea229e commit 49c07f9

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

openwisp_controller/config/handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def devicegroup_delete_handler(instance, **kwargs):
105105
if not instance.common_name or organization is None:
106106
return
107107
kwargs["common_name"] = instance.common_name
108-
kwargs["organization_slug"] = organization.slug
108+
organization = instance.organization
109+
if organization is not None:
110+
kwargs["organization_slug"] = organization.slug
109111
else:
110112
kwargs["organization_id"] = instance.organization_id
111113
instance_id = instance.id

openwisp_controller/pki/tests/test_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from django.test import TestCase, TransactionTestCase
22
from django.urls import reverse
3+
from openwisp_users.tests.test_api import AuthenticationMixin
4+
from openwisp_users.tests.utils import TestOrganizationMixin
5+
from openwisp_utils.tests import AssertNumQueriesSubTestMixin, capture_any_output
36
from packaging.version import parse as parse_version
47
from rest_framework import VERSION as REST_FRAMEWORK_VERSION
58
from swapper import load_model
@@ -247,7 +250,7 @@ def test_cert_detail_api(self):
247250
def test_cert_delete_api(self):
248251
cert1 = self._create_cert(name="cert1")
249252
path = reverse("pki_api:cert_detail", args=[cert1.pk])
250-
with self.assertNumQueries(6):
253+
with self.assertNumQueries(5):
251254
r = self.client.delete(path)
252255
self.assertEqual(r.status_code, 204)
253256
self.assertEqual(Cert.objects.count(), 0)

0 commit comments

Comments
 (0)