summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2022-12-01 20:23:43 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-15 06:17:57 +0100
commit09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca (patch)
tree15bb8bb049f9339f30d637e78b340473c2038126 /django/db/models
parentd44ee518c4c110af25bebdbedbbf9fba04d197aa (diff)
Fixed #33308 -- Added support for psycopg version 3.
Thanks Simon Charette, Tim Graham, and Adam Johnson for reviews. Co-authored-by: Florian Apolloner <florian@apolloner.eu> Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/fields/__init__.py4
-rw-r--r--django/db/models/functions/comparison.py10
-rw-r--r--django/db/models/functions/text.py18
-rw-r--r--django/db/models/lookups.py2
4 files changed, 30 insertions, 4 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index cd995de80f..991db8d707 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -2019,6 +2019,10 @@ class IntegerField(Field):
"Field '%s' expected a number but got %r." % (self.name, value),
) from e
+ def get_db_prep_value(self, value, connection, prepared=False):
+ value = super().get_db_prep_value(value, connection, prepared)
+ return connection.ops.adapt_integerfield_value(value, self.get_internal_type())
+
def get_internal_type(self):
return "IntegerField"
diff --git a/django/db/models/functions/comparison.py b/django/db/models/functions/comparison.py
index eb1f20a77c..de7eef4cdc 100644
--- a/django/db/models/functions/comparison.py
+++ b/django/db/models/functions/comparison.py
@@ -1,6 +1,7 @@
"""Database functions that do comparisons or type conversions."""
from django.db import NotSupportedError
from django.db.models.expressions import Func, Value
+from django.db.models.fields import TextField
from django.db.models.fields.json import JSONField
from django.utils.regex_helper import _lazy_re_compile
@@ -158,7 +159,14 @@ class JSONObject(Func):
return super().as_sql(compiler, connection, **extra_context)
def as_postgresql(self, compiler, connection, **extra_context):
- return self.as_sql(
+ copy = self.copy()
+ copy.set_source_expressions(
+ [
+ Cast(expression, TextField()) if index % 2 == 0 else expression
+ for index, expression in enumerate(copy.get_source_expressions())
+ ]
+ )
+ return super(JSONObject, copy).as_sql(
compiler,
connection,
function="JSONB_BUILD_OBJECT",
diff --git a/django/db/models/functions/text.py b/django/db/models/functions/text.py
index a54ce8f19b..34a1e81982 100644
--- a/django/db/models/functions/text.py
+++ b/django/db/models/functions/text.py
@@ -1,7 +1,7 @@
from django.db import NotSupportedError
from django.db.models.expressions import Func, Value
-from django.db.models.fields import CharField, IntegerField
-from django.db.models.functions import Coalesce
+from django.db.models.fields import CharField, IntegerField, TextField
+from django.db.models.functions import Cast, Coalesce
from django.db.models.lookups import Transform
@@ -82,6 +82,20 @@ class ConcatPair(Func):
**extra_context,
)
+ def as_postgresql(self, compiler, connection, **extra_context):
+ copy = self.copy()
+ copy.set_source_expressions(
+ [
+ Cast(expression, TextField())
+ for expression in copy.get_source_expressions()
+ ]
+ )
+ return super(ConcatPair, copy).as_sql(
+ compiler,
+ connection,
+ **extra_context,
+ )
+
def as_mysql(self, compiler, connection, **extra_context):
# Use CONCAT_WS with an empty separator so that NULLs are ignored.
return super().as_sql(
diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
index dded81da82..9e2d9373e6 100644
--- a/django/db/models/lookups.py
+++ b/django/db/models/lookups.py
@@ -568,7 +568,7 @@ class IsNull(BuiltinLookup):
raise ValueError(
"The QuerySet value for an isnull lookup must be True or False."
)
- sql, params = compiler.compile(self.lhs)
+ sql, params = self.process_lhs(compiler, connection)
if self.rhs:
return "%s IS NULL" % sql, params
else: