-
Notifications
You must be signed in to change notification settings - Fork 92
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
bulk_insert
fails when trying to insert JSON fields when used with return_model=True
#158
Comments
bulk_insert
fails when trying to insert JSON fields and return_model=True
bulk_insert
fails when trying to insert JSON fields when used with return_model=True
Photonios
added a commit
that referenced
this issue
Nov 22, 2021
`return_model=True` would break any rows with JSONField as it would try to convert from a JSON string to a Python object. However, the original input data was already partially converted. By forcing the database to return the values it inserted, we get a raw JSON string and the converted applies normally.
Photonios
added a commit
that referenced
this issue
Nov 23, 2021
`return_model=True` would break any rows with JSONField as it would try to convert from a JSON string to a Python object. However, the original input data was already partially converted. By forcing the database to return the values it inserted, we get a raw JSON string and the converted applies normally.
Photonios
added a commit
that referenced
this issue
Nov 23, 2021
`return_model=True` would break any rows with JSONField as it would try to convert from a JSON string to a Python object. However, the original input data was already partially converted. By forcing the database to return the values it inserted, we get a raw JSON string and the converted applies normally.
This is fixed in v2.0.4rc2 or newer. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Having upgrade to postgres-extra
v2.0.3
bulk inserting models which contain JSON fields produces the following error:This seems to be due to double converting JSON to be inserted into a JSON field. We have a JSON field defined on the model we're inserting: https://gitlab.developers.cam.ac.uk/uis/devops/iam/card-database/card-api/-/blob/master/card/models.py#L315.
We're bulk inserting using
return_model=True
which seems to cause this problem: https://gitlab.developers.cam.ac.uk/uis/devops/iam/card-database/card-api/-/blob/master/card/bulk.py#L99.Removing
return_model=True
allows the bulk insert to work, but unfortunately our bulk insert logic requires that we have access to the created models.This is likely caused by the change made in 1fccf9a#diff-cc2bc273189507c98734a1ddaddcee3a8f206c7dee9de8ef1ceffa71f71ad0d6. Seeing as adding
apply_converters=False
to the call to_create_model_instance
made inbulk_insert
stops this error from occurring.The text was updated successfully, but these errors were encountered: