summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-08-28 07:56:04 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-08-28 19:09:46 +0200
commit0be51d2226fce030ac9ca840535a524f41e9832c (patch)
treef169982fe9af369944ac3130c9a50c675929dc1f /django/db/backends/postgresql
parent22105391424cc56f29f153bb76d6a15246152674 (diff)
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.
Diffstat (limited to 'django/db/backends/postgresql')
-rw-r--r--django/db/backends/postgresql/base.py5
-rw-r--r--django/db/backends/postgresql/operations.py3
2 files changed, 4 insertions, 4 deletions
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):
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index a3442231af..1ce5755bf5 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -74,9 +74,6 @@ class DatabaseOperations(BaseDatabaseOperations):
def time_trunc_sql(self, lookup_type, field_name):
return "DATE_TRUNC('%s', %s)::time" % (lookup_type, field_name)
- def json_cast_text_sql(self, field_name):
- return '(%s)::text' % field_name
-
def deferrable_sql(self):
return " DEFERRABLE INITIALLY DEFERRED"