Skip to content

Commit

Permalink
[fix] Allow updating templates with invalid configurations
Browse files Browse the repository at this point in the history
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 bd3d11a)
  • Loading branch information
pandafy authored and nemesifier committed Dec 23, 2024
1 parent 07aa481 commit adc6eab
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions openwisp_controller/config/tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit adc6eab

Please sign in to comment.