Opened 6 years ago

Last modified 6 years ago

#29687 closed Cleanup/optimization

Support serialising JSON types other than objects in Django Test Client — at Version 5

Reported by: Dan Palmer Owned by: nobody
Component: Testing framework Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Dan Palmer)

This is a follow up to #29082, which added support for serialising JSON objects in the Django Test Client.

Currently JSON types other than objects are not supported.

This is my first ticket (I think), so any advice on what's required would be appreciated. I'm planning to open a PR on GitHub for this.

Change History (5)

comment:1 by Tim Graham, 6 years ago

Type: UncategorizedCleanup/optimization

Does using a custom encoder with test client's json_encoder parameter solve your issue?

comment:2 by Dan Palmer, 6 years ago

It doesn't - the bug is in the detection in the test client of whether to serialise with the encoder or not. I've fixed it in https://github.com/django/django/pull/10313

Help with documentation practices in that PR would be much appreciated!

Last edited 6 years ago by Dan Palmer (previous) (diff)

comment:3 by Adam Johnson, 6 years ago

This isn't a bug on 2.1, but the docs could be marginally clearer by saying it *only* happens when data is a dictionary.

Adding support for detecting arrays would be a 2.2 feature. But then it should probably detect all other types that json.dumps can do too - booleans, integers, floats, and strings? This could break more workflows, especially subtly as json.dumps on a string will normally just yield extra quote marks.

comment:4 by Dan Palmer, 6 years ago

Great, I'll update the ticket/PR for that and document it as a 2.2 feature.

comment:5 by Dan Palmer, 6 years ago

Description: modified (diff)
Summary: Support serialising JSON arrays in Django Test ClientSupport serialising JSON types other than objects in Django Test Client
Note: See TracTickets for help on using tickets.
Back to Top