mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #34080 -- Fixed __exact lookup when nested arrays contain only NULL values.
Thanks jerch and David Sanders for reviews.
This commit is contained in:
committed by
Mariusz Felisiak
parent
34d63d5a41
commit
3dc9f3ac69
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user