#34080: __exact lookup on nested arrays with None values fails on PostgreSQL.
----------------------------------+------------------------------------
Reporter: Ion Alberdi | Owner: nobody
Type: Bug | Status: new
Component: contrib.postgres | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Ion Alberdi):
Replying to [comment:1 Mariusz Felisiak]:
> Thanks for the report (see related
84633905273fc916e3d17883810d9969c03f73c2 and #27808). It's an issue in
[https://github.com/django/django/blob/84206607d6bfd61e7f7a88b51163ffd4153e3b5a/django/contrib/postgres/fields/array.py#L238-L252
ArrayRHSMixin].
Actually by running both test cases (bug=None nested array, fix=nested
array with one element that is not null.
{{{
def test_exact_nested_null(self):
instance =
NullableIntegerArrayModel.objects.create(field_nested=[[None, None],
[None, None]])
self.assertSequenceEqual(
NullableIntegerArrayModel.objects.filter(field_nested=[[None,
None], [None, None]]), [instance]
)
def test_exact_nested_null_and_not_null(self):
instance =
NullableIntegerArrayModel.objects.create(field_nested=[[None, 1], [None,
None]])
self.assertSequenceEqual(
NullableIntegerArrayModel.objects.filter(field_nested=[[None,
1], [None, None]]), [instance]
)
}}}
{{{
class ArrayRHSMixin:
def __init__(self, lhs, rhs):
if isinstance(rhs, (tuple, list)):
expressions = []
for value in rhs:
if not hasattr(value, "resolve_expression"):
field = lhs.output_field
value = Value(field.base_field.get_prep_value(value))
expressions.append(value)
rhs = Func(
*expressions,
function="ARRAY",
template="%(function)s[%(expressions)s]",
)
super().__init__(lhs, rhs)
}}}
By looking at the rhs variable in both scenarios:
- test_exact_nested_null(bug)
{{{
Func(Value([None, None]), Value([None, None]), function=ARRAY,
template=%(function)s[%(expressions)s])
}}}
- test_exact_nested_null_and_not_null(correct)
{{{
Func(Value([None, 1]), Value([None, None]), function=ARRAY,
template=%(function)s[%(expressions)s])
}}}
The rhs variables look correct to me. I'll continue digging, so far I tend
to go towards the psycopg2 bug hypothesis. Thanks a lot for these links
Marius,
https://github.com/psycopg/psycopg2/issues/325 seems indeed to be pretty
related to this one.
--
Ticket URL: <https://code.djangoproject.com/ticket/34080#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070183c1a2bcba-cb1cbe74-3eee-4cb9-9478-0fa6c95d71e7-000000%40eu-central-1.amazonses.com.