diff options
author | Ion Alberdi <ion.alberdi@pricemoov.com> | 2022-10-09 11:01:14 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-11-03 06:59:49 +0100 |
commit | 3dc9f3ac6960c83cd32058677eb0ddb5a5e5da43 (patch) | |
tree | 497cad64b6608b1d3f527cdc6f068cb63c0e1eba /django/contrib/postgres/fields/array.py | |
parent | 34d63d5a41188a32b77733e33c1fad64f37c6772 (diff) | |
download | django-3dc9f3ac6960c83cd32058677eb0ddb5a5e5da43.tar.gz |
Fixed #34080 -- Fixed __exact lookup when nested arrays contain only NULL values.
Thanks jerch and David Sanders for reviews.
Diffstat (limited to 'django/contrib/postgres/fields/array.py')
-rw-r--r-- | django/contrib/postgres/fields/array.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index 3edc72ac94..c247387eb7 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -237,7 +237,9 @@ class ArrayField(CheckFieldDefaultMixin, Field): class ArrayRHSMixin: def __init__(self, lhs, rhs): - if isinstance(rhs, (tuple, list)): + # Don't wrap arrays that contains only None values, psycopg2 doesn't + # allow this. + if isinstance(rhs, (tuple, list)) and any(self._rhs_not_none_values(rhs)): expressions = [] for value in rhs: if not hasattr(value, "resolve_expression"): @@ -256,6 +258,13 @@ class ArrayRHSMixin: cast_type = self.lhs.output_field.cast_db_type(connection) return "%s::%s" % (rhs, cast_type), rhs_params + def _rhs_not_none_values(self, rhs): + for x in rhs: + if isinstance(x, (list, tuple)): + yield from self._rhs_not_none_values(x) + elif x is not None: + yield True + @ArrayField.register_lookup class ArrayContains(ArrayRHSMixin, lookups.DataContains): |