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

Use strict float handling in JSON functions #5265

Merged
merged 7 commits into from
Sep 25, 2017

Conversation

rpkilby
Copy link
Member

@rpkilby rpkilby commented Jul 10, 2017

Resolve #4918, fix #5235. The important bits that I gathered from the discussion were:

  • DRF should internally encode/decode only strict JSON, since other modules (eg, postgres's JSONField) may not be compatible with the extended float values (Infinity, NaN). Incompatible values should raise an exception.
  • Users may still want to render/parse extended JSON.

This PR does the following:

  • Adds an internal rest_framework.utils.json module that defaults to strict JSON encoding/decoding.
  • All imports have been changed to rest_framework.utils.json, so they obey the stricter behavior.
  • Adds flake8-tidy-imports, which allows us direct users to import the json wrapper module.
  • Adds settings.STRICT_JSON, which controls the strictness of JSONParser & JSONRenderer. This defaults to True, but users can revert to the old extended behavior by setting this to False

Ryan P Kilby added 4 commits July 10, 2017 16:55
STRICT_JSON controls the renderer & parser behavior on whether or not
to accept non-standard float values (NaN, Infinity).
@rpkilby
Copy link
Member Author

rpkilby commented Jul 10, 2017

@sbchisholm, @andyneff - does this provide the expected behavior?

@tomchristie tomchristie added this to the 3.7.0 Release milestone Jul 11, 2017
@@ -0,0 +1,33 @@

Copy link
Member

Choose a reason for hiding this comment

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

Worth a docstring here to highlight why we have this module.

@tomchristie
Copy link
Member

This is ace. Nice work @rpkilby!

@tomchristie
Copy link
Member

Looks great. Deferring to 3.7.0.

@carltongibson carltongibson merged commit ea894cd into encode:master Sep 25, 2017
@rpkilby rpkilby deleted the json-unextension branch September 25, 2017 07:15
carltongibson added a commit that referenced this pull request Sep 25, 2017
Strict JSON handling
carltongibson added a commit that referenced this pull request Sep 26, 2017
Strict JSON handling
carltongibson added a commit that referenced this pull request Sep 27, 2017
Strict JSON handling
carltongibson added a commit that referenced this pull request Sep 28, 2017
Strict JSON handling
carltongibson added a commit that referenced this pull request Oct 5, 2017
Strict JSON handling
carltongibson added a commit that referenced this pull request Oct 5, 2017
Strict JSON handling
carltongibson pushed a commit that referenced this pull request Oct 6, 2017
* Set version number for 3.7.0 release

* Rename release notes section

Moved issue links to top for easier access.
(Can move back later)

* Add release note for #5273

* Add release note for #5440

* Add release note for #5265

Strict JSON handling

* Add release note for #5250

* Add release notes for #5170

* Add release notes for #5443

* Add release notes for #5448

* Add release notes for #5452

* Add release not for #5342

* Add release notes for 5454

* Add release notes for #5058 & #5457

Remove Django 1.8 & 1.9 from README and setup.py

* Release notes for merged 3.6.5 milestone tickets

Tickets migrated to 3.7.0 milestone.

* Add release notes for #5469

* Add release notes from AM 2ndOct

* Add final changes to the release notes.

* Add date and milestone link

Move issue links back to bottom.

* Update translations from transifex

* Begin releae anouncement

* Add release note for #5482

* 3.7 release announcement & related docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSONField: Infinity, -Inifinity, NaN are not compatible with Postgres' JSON field
3 participants