From 9df33cef8b2d4a5672e0917a66f58a4af9615ed9 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 18 Sep 2018 11:46:22 -0400 Subject: [PATCH] Fixes #2443: Enforce JSON object format when creating config contexts --- CHANGELOG.md | 1 + netbox/extras/models.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db5120ead..8a665e893 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ v2.4.5 (FUTURE) ## Bug Fixes * [#2406](https://github.com/digitalocean/netbox/issues/2406) - Remove hard-coded limit of 1000 objects from API-populated form fields +* [#2443](https://github.com/digitalocean/netbox/issues/2443) - Enforce JSON object format when creating config contexts --- diff --git a/netbox/extras/models.py b/netbox/extras/models.py index ad4fcdb18..cf4d646f3 100644 --- a/netbox/extras/models.py +++ b/netbox/extras/models.py @@ -700,6 +700,14 @@ class ConfigContext(models.Model): def get_absolute_url(self): return reverse('extras:configcontext', kwargs={'pk': self.pk}) + def clean(self): + + # Verify that JSON data is provided as an object + if type(self.data) is not dict: + raise ValidationError( + {'data': 'JSON data must be in object form. Example: {"foo": 123}'} + ) + class ConfigContextModel(models.Model):