From 0be51d2226fce030ac9ca840535a524f41e9832c Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 28 Aug 2020 07:56:04 +0200 Subject: Fixed #31956 -- Fixed crash of ordering by JSONField with a custom decoder on PostgreSQL. Thanks Marc Debureaux for the report. Thanks Simon Charette, Nick Pope, and Adam Johnson for reviews. --- django/db/backends/postgresql/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'django/db/backends/postgresql/base.py') diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index ed911a91da..03c7a3c284 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -200,7 +200,10 @@ class DatabaseWrapper(BaseDatabaseWrapper): # Set the isolation level to the value from OPTIONS. if self.isolation_level != connection.isolation_level: connection.set_session(isolation_level=self.isolation_level) - + # Register dummy loads() to avoid a round trip from psycopg2's decode + # to json.dumps() to json.loads(), when using a custom decoder in + # JSONField. + psycopg2.extras.register_default_jsonb(conn_or_curs=connection, loads=lambda x: x) return connection def ensure_timezone(self): -- cgit v1.3