Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16640 fix JSON custom field save nul #16713

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

arthanson
Copy link
Collaborator

Fixes: #16640

This will fix new saves, doesn't go back and fix old values - could set it to UI editable and edit it to fix. If you have saved multiple times then it will keep escaping so not sure if more dangerous to auto-fix with a validate as JSON and if not valid then revert to ''...

@arthanson arthanson marked this pull request as ready for review June 25, 2024 14:13
@@ -39,7 +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:
form_field.initial = json.dumps(initial)
form_field.initial = json.dumps(initial) if initial else ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to check against None explicitly, because e.g. 0 would be a valid value.

Suggested change
form_field.initial = json.dumps(initial) if initial else ''
form_field.initial = json.dumps(initial) if initial is not None else ''

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that wouldn't be valid JSON, I think you have to have key:value for valid JSON which would never evaluate to False?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK you can store arbitrary scalars like 123 or "foo" in the field too.

@FliesLikeABrick
Copy link

Hi all, I am the reported of the original issue. This PR appears to fix the issue for null values only. Editing existing values, or creating a prefix with a default value both lead to escaped strings being placed in the field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI corrupts read-only JSON fields
3 participants