Opened 3 years ago
Closed 3 years ago
#34548 closed Bug (invalid)
Queryset JsonField filtering doesn't work as expected
| Reported by: | Michael | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 4.2 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hello. I use Django 4.2, psycopg2 2.9.6 and postgis/postgis:15-3.3-alpine as database in my project.
Previously json field filtering worked as expected
extra_data__hello="world"
returned me queryset where objects extra_data json field contained {"hello": "world"}. Now I noticed queryset is empty. After some manipulations with query it start work after adding "iexact".
I expected if json field is {"hello": "world"},
objects.filter(extra_data__hello="world")
or
objects.filter(extra_data__hello=some_variable)
should return this object in query set, but it doesn't work. objects.filter(extra_datahelloiexact="world") fix this problem.
Here are queries example:
>>> token='world'
>>> str(UserSocialAuth.objects.filter(extra_data__hello__exact=token).query)
'SELECT "social_auth_usersocialauth"."id", "social_auth_usersocialauth"."user_id", "social_auth_usersocialauth"."provider", "social_auth_usersocialauth"."uid", "social_auth_usersocialauth"."extra_data", "social_auth_usersocialauth"."created", "social_auth_usersocialauth"."modified" FROM "social_auth_usersocialauth" WHERE ("social_auth_usersocialauth"."extra_data" -> hello) = \'"\\"world\\""\''
>>> str(UserSocialAuth.objects.filter(extra_data__hello__iexact=token).query)
'SELECT "social_auth_usersocialauth"."id", "social_auth_usersocialauth"."user_id", "social_auth_usersocialauth"."provider", "social_auth_usersocialauth"."uid", "social_auth_usersocialauth"."extra_data", "social_auth_usersocialauth"."created", "social_auth_usersocialauth"."modified" FROM "social_auth_usersocialauth" WHERE UPPER(("social_auth_usersocialauth"."extra_data" ->> hello)::text) = UPPER(world)'
Could you give me advice how to fix this issue?
Thank you
Change History (2)
comment:1 by , 3 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Thanks for the report, however I cannot replicate the issue described.
If you need support in debugging your issue please refer to one of the support channels for assistance: https://www.djangoproject.com/community/
code fixes