JSONField cannot process empty value from html form on browsable API #8822
Unanswered
giff-h
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given this example setup:
example/models.py
example/views.py
example/urls.py
Navigate to it and everything looks good
Clear the fields,
POST
, and it returns 400.After stepping through the code in a debugger, it appears that it's interpreting the empty string input as a JSON string, and obviously it'll be invalid.
field_value = '""'
is valid JSON empty string,field_value = ''
is invalid JSON. IMO it should be interpreting empty string field values as literallyempty
to align with expectations of HTML forms.I present this as a possible fix. Obviously tests should be added to cover various cases and prevent regression, but this is what currently exists:
rest_framework/fields.py
This is what I'm thinking of:
Beta Was this translation helpful? Give feedback.
All reactions