From 2921c7302c990f67a826fb1d707a9a64720dd71b Mon Sep 17 00:00:00 2001 From: David McDonald Date: Wed, 21 Oct 2020 11:14:23 +0100 Subject: [PATCH 1/2] Fix incorrect redis key deleting We were trying to delete the old 'template-{template-id}' keys but should have been deleting the new keys which have the service id as part of the key name. This was causing the cache to not be correctly purged when we did things like update sender names or set defaults. This should fix it. --- app/notify_client/service_api_client.py | 2 +- tests/app/notify_client/test_service_api_client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index ecf7befe2..abc31446b 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -10,7 +10,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): templates_for_service = self.get_service_templates(service_id)['data'] if templates_for_service: redis_client.delete(*[ - f"template-{x['id']}-version-None" + f"service-{service_id}-template-{x['id']}-version-None" for x in templates_for_service ]) diff --git a/tests/app/notify_client/test_service_api_client.py b/tests/app/notify_client/test_service_api_client.py index e21ae2dac..d7ca81e3a 100644 --- a/tests/app/notify_client/test_service_api_client.py +++ b/tests/app/notify_client/test_service_api_client.py @@ -550,5 +550,5 @@ def test_client_deletes_service_template_cache_when_service_is_updated( templates_to_delete = mock_redis_delete.call_args_list[0][0] assert len(templates_to_delete) == 6 for template_key in templates_to_delete: - assert template_key.startswith('template-') + assert template_key.startswith('service-{}-template'.format(SERVICE_ONE_ID)) assert template_key.endswith('version-None') From 922d43ea1a47eb8db773b32340c4a5a947218e3e Mon Sep 17 00:00:00 2001 From: David McDonald Date: Wed, 21 Oct 2020 11:18:09 +0100 Subject: [PATCH 2/2] Update tests/app/notify_client/test_service_api_client.py Co-authored-by: Chris Hill-Scott --- tests/app/notify_client/test_service_api_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/app/notify_client/test_service_api_client.py b/tests/app/notify_client/test_service_api_client.py index d7ca81e3a..4a2ef83b8 100644 --- a/tests/app/notify_client/test_service_api_client.py +++ b/tests/app/notify_client/test_service_api_client.py @@ -550,5 +550,5 @@ def test_client_deletes_service_template_cache_when_service_is_updated( templates_to_delete = mock_redis_delete.call_args_list[0][0] assert len(templates_to_delete) == 6 for template_key in templates_to_delete: - assert template_key.startswith('service-{}-template'.format(SERVICE_ONE_ID)) + assert template_key.startswith(f'service-{SERVICE_ONE_ID}-template') assert template_key.endswith('version-None')