﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31829	Chaining KeyTransform with 'contains' lookup uses builtin lookup instead of overridden lookup	Sage Abdullah	Sage Abdullah	"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""`."	Bug	closed	Database layer (models, ORM)	3.1	Release blocker	fixed			Ready for checkin	1	0	0	0	0	0
