-
Notifications
You must be signed in to change notification settings - Fork 182
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
simplejson incorrectly returns byte strings in many cases #369
Comments
You are not required to include
I would love to hear @etrepum reply to your claims. |
We don't require simplejson either, but some of our dependencies do. |
Forcing the return of unicode objects to simplejson can be done by providing unicode input. It will only return str objects for ASCII text, which is generally interchangeable with unicode objects (they even hash the same) except when explicit type checks are done. This is a (significant) speed and space optimization, since Python 2 doesn't have the same sort of flexible unicode representation that Python 3 does. |
@etrepum Always passing in unicode is certainly an option, but that would have to be done by the riak HTTP transport implementation since that is what calls |
P.S. I'm happy to create a pull request for either of my suggestions. I'd just like an indication that it has some chance of landing before I start. P.P.S. We have to work around this anyway because we have production code that is breaking because of this right now. We've uninstalled |
It's probably best to consolidate all of the JSON that the riak client does and parameterize it such that you can provide some object with loads and dumps methods to the constructor and it'll just use that everywhere. This way you can parameterize the behavior to be exactly what suits your use case, whether that's specifying different options than the defaults or swapping out the implementation entirely. |
I agree, @etrepum, that seems the best course of action. @hodgestar If you have time for a pull-request, we'd appreciate it, otherwise it seems reasonable enough that we'll include it in the next development cycle. |
Awesome! Thanks. Will try get a PR cut later in the week. |
A fix for this should probably also include the |
The JSON specification defines JSON strings as:
The natural Python analog of these appears to be Python unicode strings. Confusingly, the
simplejson
library sometimes returns unicode strings and sometimes byte strings, e.g.:This makes writing correct code on top of
simplejson
rather hard.Riak uses
simplejson
in two kinds of places -- firstly, for decoding object data in the client. These allow for overriding the default encoders and so are less of an issue. Secondly, in the HTTP transport for decoding JSON responses. These provide no means to control the JSON parser used and return decoded keys and indexes in many places.For the HTTP transport could we either:
The text was updated successfully, but these errors were encountered: