-
Notifications
You must be signed in to change notification settings - Fork 270
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
Can not store ordinary Python strings in JSONfield #33
Comments
From my point of view, this additional test shall pass:
|
Hey @jrief you are correct that a regular string should be valid. I'll look into this––thanks for the test. |
Just an idea on how to solve it. |
Hey @jrief sorry for the delay on this. I'm not crazy about storing elements in a list for backward compatibility reasons––I'd love to find a cleaner way to do this. I'm going to spend some time working/thinking on this and try to figure out a solution. |
Closing as this was fixed in e7978a0 |
Hi, It seems this issue is not totally fixed, I can't store strings with specific values like "123" or "false", strings are converted to integer or boolean. I have added two new tests to illustrate this: lmeunier/django-jsonfield@8e6e915a37a1a38c00fa86f34a0d3462932cacaa |
The problem is that in |
I spent some time looking into this and didn't come away with great results. As you said @jrief it seems I found someone experiencing a similar problem (http://stackoverflow.com/questions/4510162/django-custom-field-only-run-to-python-on-values-from-db/7668745#7668745) and their solution was to prepend the JSON encoded string with "json:" I don't really like this solution––but as of right now this is the only thing I've found that might work. I'm going to spend some more time looking into this, but wanted to see what everyone else thought about this approach. |
Thanks for looking at this issue @bradjasper. We come to the same conclusion: we can never be sure that the string passed to The solution to prepend the JSON encoded string with "json:" should work for every cases except one: I can't store a string beginning with "json:". But, if it's documented somewhere, I think we could live with it. |
Strings can be serialized just fine in JSON, so the problem, as I understand it, is that Django is badly designed such that it applies the database deserialization method even to values that are set directly by Python? So when you write In that case, this is really a problem with Django and we should be discussing this on their issue tracker. In theory it should be easy to add a feature that lets you choose different methods for processing values from the database and values from Python itself. |
@fletom Yes, from my point of view this is a Django issue, not an issue of this module. |
@jrief I have tried to put the field content into a list of length 1, but then you can't store a string formatted like this @fletom I would love to open a ticket in Django, but my english is too bad to explain the problem clearly :) |
I posted a quick message to the django-users mailing list to see if anyone there had feedback before escalating to the Django issue tracker: https://groups.google.com/forum/?fromgroups=#!topic/django-users/UORVadDO61w |
I've posted this to the Django bug tracker: https://code.djangoproject.com/ticket/20090#ticket |
Thanks, I'll watch this ticket. |
@bradjasper Many thanks for the fix. From my point of view, all is ok now. |
Strings again can't be saved with JSONField. With Django 1.7.4 and django-jsonfield 0.9.13 I get:
|
👍 didn't work for me either |
Since version 0.9.4 I am not able to store ordinary Python strings in a JSONfield. Up to version 0.9.2 this worked without problems.
Did I miss something? From my point of view, it should not matter, if I store ordinary strings, lists or dicts in a JSONfield.
The text was updated successfully, but these errors were encountered: