Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Fix to work in parallel with django.contrib.postgres.JSONField #5

Closed
adamchainz opened this issue Mar 16, 2019 · 4 comments · Fixed by #14
Closed

Fix to work in parallel with django.contrib.postgres.JSONField #5

adamchainz opened this issue Mar 16, 2019 · 4 comments · Fixed by #14

Comments

@adamchainz
Copy link
Owner

See https://bitbucket.org/schinckel/django-jsonfield/issues/57/cannot-use-in-the-same-project-as-djangos

This issue looks complicated, there's a whole library by @kbussell to introduce that compatibility, https://github.com/kbussell/django-jsonfield-compat . The technique it uses should probably be merged in here!

@jakeatallyo
Copy link

What is the status of this bug? When can we expect a solution?

@adamchainz
Copy link
Owner Author

adamchainz commented Jun 2, 2019 via email

@laymonage
Copy link
Contributor

I believe it's because of this line https://github.com/adamchainz/django-jsonfield/blob/master/jsonfield/fields.py#L198

The registration is shared on the same database connection (see https://github.com/psycopg/psycopg2/blob/master/lib/_json.py#L93), so it'll interfere with contrib.postgres.

A fix I'd propose is to use select_format. I'm using it in my draft of JSONField for Django here: https://github.com/django/django/blob/f5674d94b2ce0447158d63e61ea011b235744446/django/db/models/fields/json.py#L76.

Might worth a look if @jakeatallyo (or anyone else) is looking for a quick fix.

@adamchainz
Copy link
Owner Author

@laymonage thank you for that comment. If you have some spare time it would be great if you could create a PR for that fix and test it alongside current and future Django JSONFields. You are the world expert now :)

adamchainz pushed a commit that referenced this issue Aug 18, 2019
Fix #5.

Instead of registering a no-op `loads()` to avoid psycopg2's automatic decoding, we cast the value into `text`. As [the docs](http://initd.org/psycopg/docs/extras.html#json-adaptation) say, it is an efficient operation that doesn’t involve a copy.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants