#31829 closed Bug (fixed)
Chaining KeyTransform with 'contains' lookup uses builtin lookup instead of overridden lookup
Reported by: | Sage Abdullah | Owned by: | Sage Abdullah |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.1 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The previous implementation of django.contrib.postgres.fields.JSONField
, when chained with a KeyTransform
and a contains
lookup, uses the overridden contains
lookup that is JSON-based and not the builtin one that is pattern-based.
Using the example model in the 3.1 release notes,
class ContactInfo(models.Model): data = models.JSONField() obj = ContactInfo.objects.create(data={ 'name': 'John', 'cities': ['London', 'Cambridge'], 'pets': {'dogs': ['Rufus', 'Meg']}, }) ContactInfo.objects.filter( data__cities__contains='Cambridge', )
The query returns a queryset with obj
in it, which is expected.
However, the following query:
ContactInfo.objects.filter( data__cities__contains='bridge', )
Also returns a queryset with obj
in it. Using the previous implementation, obj
doesn't match the query because contains
uses JSON-based containment checking. That is, it checks whether the array in data__cities
contains an element that's exactly "bridge"
.
Change History (9)
comment:1 by , 4 years ago
Description: | modified (diff) |
---|
comment:2 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 4 years ago
Has patch: | set |
---|
comment:4 by , 4 years ago
Patch needs improvement: | set |
---|---|
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
Version: | master → 3.1 |
comment:5 by , 4 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
PR