Skip to content

Commit

Permalink
16640 convert JSON field from str to dict
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanson committed Jul 29, 2024
1 parent 1c380aa commit cb8fdbe
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions netbox/netbox/forms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ def _get_form_field(self, customfield):
form_field = customfield.to_form_field(set_initial=False)
initial = self.instance.custom_field_data.get(customfield.name)
if customfield.type == CustomFieldTypeChoices.TYPE_JSON:
if initial is not None:
form_field.initial = json.dumps(initial)
else:
form_field.initial = ''
form_field.initial = json.dumps(initial)
else:
form_field.initial = initial
return form_field
Expand All @@ -63,6 +60,8 @@ def clean(self):
if value in self.fields[cf_name].empty_values:
self.instance.custom_field_data[key] = None
else:
if customfield.type == CustomFieldTypeChoices.TYPE_JSON and type(value) is str:
value = json.loads(value)
self.instance.custom_field_data[key] = customfield.serialize(value)

return super().clean()
Expand Down

0 comments on commit cb8fdbe

Please sign in to comment.