From 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 1 Dec 2022 20:23:43 +0100 Subject: Fixed #33308 -- Added support for psycopg version 3. Thanks Simon Charette, Tim Graham, and Adam Johnson for reviews. Co-authored-by: Florian Apolloner Co-authored-by: Mariusz Felisiak --- django/contrib/postgres/fields/array.py | 2 +- django/contrib/postgres/fields/ranges.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'django/contrib/postgres/fields') diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index eaff032465..8477dd9fff 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -237,7 +237,7 @@ class ArrayField(CheckFieldDefaultMixin, Field): class ArrayRHSMixin: def __init__(self, lhs, rhs): - # Don't wrap arrays that contains only None values, psycopg2 doesn't + # Don't wrap arrays that contains only None values, psycopg doesn't # allow this. if isinstance(rhs, (tuple, list)) and any(self._rhs_not_none_values(rhs)): expressions = [] diff --git a/django/contrib/postgres/fields/ranges.py b/django/contrib/postgres/fields/ranges.py index d5c438dbdc..fbb6012660 100644 --- a/django/contrib/postgres/fields/ranges.py +++ b/django/contrib/postgres/fields/ranges.py @@ -9,6 +9,7 @@ from django.db.backends.postgresql.psycopg_any import ( NumericRange, Range, ) +from django.db.models.functions import Cast from django.db.models.lookups import PostgresOperatorLookup from .utils import AttributeSetter @@ -208,7 +209,14 @@ class DateRangeField(RangeField): return "daterange" -RangeField.register_lookup(lookups.DataContains) +class RangeContains(lookups.DataContains): + def get_prep_lookup(self): + if not isinstance(self.rhs, (list, tuple, Range)): + return Cast(self.rhs, self.lhs.field.base_field) + return super().get_prep_lookup() + + +RangeField.register_lookup(RangeContains) RangeField.register_lookup(lookups.ContainedBy) RangeField.register_lookup(lookups.Overlap) -- cgit v1.3