-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Do not use canonicaljson to magically handle decoding bytes from JSON #7802
Conversation
changelog.d/4802.misc
Outdated
@@ -0,0 +1 @@ | |||
Switch from simplejson to the standard library json. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches #7800, seemed silly to have a separate changelog entry for changing a comment. :)
6dee862
to
ea37297
Compare
There's some similar instances of this so I'll group it into this same PR. |
6fd514f
to
f792456
Compare
I'm curious on people's thoughts here, especially whether it makes sense to have a single function which handles |
I kinda feel like making the Not a strong opinion though. |
That works too. I actually originally made a separate function for error handling reasons, but then realized that both |
Part of my reasoning was also that I was assuming that once we dropped support for Python 3.5 we wouldn't do the decoding and would just pass it directly into |
I think this is ready now, as I mentioned above this doesn't try to hit every instance, but some of the core areas. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* commit '66a4af8d9': Do not use canonicaljson to magically handle decoding bytes from JSON. (#7802)
Related to #7674,
this is another reference to simplejson that can go away.Unfortunately we can't actually remove this code until Python 3.6, which is whenjson
gained support for parsing bytes directly. (Note that simplejson does actually parse both bytes and str.)This adds a shim for decoding JSON from bytes. If Python 3.5 is not supported in the future we can switch to directly usingjson.loads
.This adds manual decoding of bytes to UTF-8 to be compatible with Python 3.5.
This only converts a couple of callers since this is a bit nuanced. Annoyingly there's a potential to actually break Python 3.6/3.7 here since you can't
decode
astr
. We could add a type check and handlebytes
orstr
as the input to the function if we think that would be better.This attempts to handle some of our more generic code:
HttpResponseException
)It also corrects a type hint in the CAS handler.