-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Render JSON fields with proper indentation in browsable API forms. #6243
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
Render JSON fields with proper indentation in browsable API forms. #6243
Conversation
6c568fa
to
34b6dce
Compare
When using json.dumps with indenting, in python2 the default formatting prints whitespace after commas (,) and python3 does not. This can be unified with the separators keyword argument.
34b6dce
to
e532cdd
Compare
Can we get this merged? |
Something I had to add to have the proper behaviour in the browsable API was special checking for nulls and errors:
|
Yeah seems like a decent improvement actually. Thanks! |
@tomchristie My comment was intended as a hint of what we needed to add for proper rendering of nulls and errors for json fields in the browsable api. Do you think that this would help? |
Not sure, it's not clear enough to me from the comment what the actual effect/change is that you're suggesting. (From a quick scan) |
Right now, the browsable API has the following behaviour for json fields for nested bound fields:
While not a big issue, this is a nuissance when testing out the browsable API and you mistyped before sending a request as you have to manually fix the error in your payload as well as the extra quotes around it that were introduced by drf. EDIT: I will produce screenshots. |
Not sure. We might consider it, tho I don't know if the complexity is worth it or not. We're a big ol' clunky framework as things are, and sometimes it might be worth us just letting a few of these niggles pass, vs. adding extra code workarounds. 🤷♂️ Prob needs a fresh discussion if you're keen on pushing for it, and see if others have any feedback. (?) |
I don't see it as a big showstopper for us, we have found the workaround and use it in the codepath we need it for. In the end it's your call. EDIT: And as this is "only" about the browsable API I understand your stance. If I come around to it I will maybe create a PR. For now, the workaround can be found here.
|
…ncode#6243) * Fix JSONBoundField usage on nested serializers (encode#6211) * Unify JSONBoundField as_form_field output between py2 and py3 When using json.dumps with indenting, in python2 the default formatting prints whitespace after commas (,) and python3 does not. This can be unified with the separators keyword argument.
…ncode#6243) * Fix JSONBoundField usage on nested serializers (encode#6211) * Unify JSONBoundField as_form_field output between py2 and py3 When using json.dumps with indenting, in python2 the default formatting prints whitespace after commas (,) and python3 does not. This can be unified with the separators keyword argument.
Description
Fixes bugs related to nested JSONField
as_form_field
rendering.Closes #6211