Skip to content

Commit a503e01

Browse files
committed
[fix] Fixed potential KeyError
1 parent 9c9a4a5 commit a503e01

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

openwisp_controller/config/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def invalidate_devicegroup_cache_delete(instance_id, model_name, **kwargs):
115115
)
116116
elif model_name == Cert._meta.model_name:
117117
DeviceGroupCommonName.certificate_delete_invalidates_cache(
118-
kwargs["common_name"], kwargs["organization_slug"]
118+
kwargs["common_name"], kwargs.get("organization_slug")
119119
)
120120

121121

openwisp_controller/config/tests/test_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,20 @@ def test_shared_cert_delete_invalidates_devicegroup_wildcard_cache(self):
10571057
common_name=common_name,
10581058
)
10591059

1060+
def test_shared_cert_delete_task_invalidates_devicegroup_wildcard_cache(self):
1061+
cert = self._create_cert(organization=None)
1062+
common_name = cert.common_name
1063+
with patch(
1064+
"openwisp_controller.config.api.views.DeviceGroupCommonName"
1065+
".certificate_delete_invalidates_cache"
1066+
) as mocked_invalidate:
1067+
tasks.invalidate_devicegroup_cache_delete(
1068+
cert.id,
1069+
Cert._meta.model_name,
1070+
common_name=common_name,
1071+
)
1072+
mocked_invalidate.assert_called_once_with(common_name, None)
1073+
10601074

10611075
class TestTransactionConfig(
10621076
CreateConfigTemplateMixin,

0 commit comments

Comments
 (0)