#31829: Chaining KeyTransform with 'contains' lookup uses builtin lookup instead of overridden lookup -------------------------------------+------------------------------------- Reporter: sage | Owner: nobody Type: Bug | Status: new Component: Database | Version: master layer (models, ORM) | Severity: Normal | Keywords: Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- The previous implementation of `django.contrib.postgres.fields.JSONField` 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"`. -- Ticket URL: <https://code.djangoproject.com/ticket/31829> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.438ac08e0d696048638681207036dd14%40djangoproject.com.