From adc6eab77232433914cbea8a4a9c45736d0202b5 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Mon, 2 Dec 2024 22:06:52 +0530 Subject: [PATCH] [fix] Allow updating templates with invalid configurations Previously, fixing an invalid template configuration via the UI was blocked due to the cache invalidation mechanism. This mechanism attempted to evaluate the existing configuration, triggering a ValidationError and preventing updates. (cherry picked from commit bd3d11a5b1e8ff62d0bbd42aef8e4a86c8015423) --- openwisp_controller/config/tests/test_template.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/openwisp_controller/config/tests/test_template.py b/openwisp_controller/config/tests/test_template.py index 53540c6ea..6848f85c8 100644 --- a/openwisp_controller/config/tests/test_template.py +++ b/openwisp_controller/config/tests/test_template.py @@ -748,3 +748,18 @@ def test_task_timeout(self, mocked_update_related_config_status): template.save() mocked_error.assert_called_once() mocked_update_related_config_status.assert_called_once() + + def test_fixing_wrong_configuration(self): + template = self._create_template() + # create a wrong configuration + Template.objects.update(config={'interfaces': [{'name': 'eth0', 'type': ''}]}) + # Ensure the configuration raises ValidationError + with self.assertRaises(NetjsonconfigValidationError): + template.refresh_from_db() + del template.backend_instance + template.checksum + + del template.backend_instance + template.config = {'interfaces': [{'name': 'eth0', 'type': 'ethernet'}]} + template.full_clean() + template.save()