Re: [Django] #32135: JSONField db_type `jsonb`==>`json` for sequential data no longer works

3 views
Skip to first unread message

Django

unread,
Oct 25, 2020, 1:43:44 AM10/25/20
to django-...@googlegroups.com
#32135: JSONField db_type `jsonb`==>`json` for sequential data no longer works
-------------------------------------+-------------------------------------
Reporter: Michael Anuzis | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by sage):

I'd like to note, if you still want to use JSON, you can register a
handler for the [https://docs.djangoproject.com/en/3.1/ref/signals
/#connection-created connection_created] signal. The handler should
register a stub loader for JSON by calling
`psycopg2.extras.register_default_json(conn_or_curs=connection,
loads=lambda x: x)`. See
[https://github.com/django/django/blob/master/django/db/backends/postgresql/base.py#L203-L206
the registration for JSONB here]. Otherwise, then you would have to
override `from_db_value` so it just returns the value because it's already
handled by psycopg2.

--
Ticket URL: <https://code.djangoproject.com/ticket/32135#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages