-
Notifications
You must be signed in to change notification settings - Fork 271
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
Error during South datamigration of raw string value #80
Comments
I'm encountering a similar issue. I'm using Postgres 9.3, so the field is stored as a json field, and I store a simple string in the json field. The deserialization checks if the returned field is a string and if so, it tries to This is wrong; there should be a check higher up that turns of deserialization for postgres json fields. |
Workaround: Convert the field type to text |
I also found a workaround, after staring at Django/JSONField for a while. In my south migration, I always serialize the the value to JSON first. This works because the bug essentially means JSONField aggressively deserializes strings (and strings only) on save. Make everything a serialized string first, and JSONField will deserialize back to the original value, which may itself be a string. Before (triggers bug): for row in orm['testapp.foo'].objects.all():
new_row = orm['testapp.bar'].objects.create(data=row.data) After: for row in orm['testapp.foo'].objects.all():
new_row = orm['testapp.bar'].objects.create(data=json.dumps(row.data)) |
Thanks @mik3y and @wmertens, I will try to get this officially cleaned up, but glad you both found workarounds. JSONField is likely moving back to TEXT columns anyway, as we've had a ton of problems trying to using the JSON column in PG. Here's a temp branch if you're interested: https://github.com/bradjasper/django-jsonfield/tree/postgresql |
In fact, changing the field to text doesn't fix it 100%, for example To be robust, the field type should be detected at init time I think.
|
I wonder if this bug is still reproducible after #85 |
@bradjasper are you still going to remove JSON field support in PostGres? It would be great to have it removed so we can upgrade to PostGres 9.3... |
This change has been made. 1.0.0 no longer supports a native JSON datatype on PostgreSQL. |
This seems to be related to issue #33.
I have written a South datamigration which simply copies one table's
JSONField
values to another table. Although it works as expected for some types, it fails when the data being migrated/saved is a plain string, with the following stack trace:I've created a minimal Django project which reproduces the issue: https://github.com/mik3y/jsonfield-datamigration-bug . It includes a database with a row triggering the problem; should be possible to check it out and run
migrate
.The text was updated successfully, but these errors were encountered: