#31936 closed Bug (fixed)
On MySQL, Oracle, and SQLite, __in lookup doesn't work on key transforms.
Reported by: | Sébastien Pattyn | Owned by: | Mariusz Felisiak |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.1 |
Severity: | Release blocker | Keywords: | JSONField SQLite MySQL |
Cc: | Sage Abdullah | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I am currently rewriting our app where we will start using models.JSONField
instead of django_mysql.models.JSONField
. I noticed that the __in
operator is not reacting the same way is it does on other fields.
first_filter = {‘our_field__key__in': [0]} first_items = OurModel.objects.filter(**first_filter) len(first_items) 0 second_filter = {'our_field__key': 0} second_items = OurModel.objects.filter(**second_filter) len(second_items ) 312
I would expect that both filters would give me the same queryset but this is not the case.
Change History (11)
comment:1 by , 4 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Summary: | JSONField not filtering correct with `__in` → JSONField not filtering correct with __in lookup on key transforms. |
comment:2 by , 4 years ago
Hi,
I noticed I forgot to mention that this error only occurs if the length of the list, where __in
is used, only contains one element.
There were no issues when the list contains more then one element. I'm currently on MySQL 5.7.
comment:3 by , 4 years ago
Cc: | added |
---|---|
Keywords: | SQLite MySQL added |
Resolution: | needsinfo |
Severity: | Normal → Release blocker |
Status: | closed → new |
Summary: | JSONField not filtering correct with __in lookup on key transforms. → On MySQL and SQLite, __in lookup doesn't work on key transforms when RHS has a single value. |
Triage Stage: | Unreviewed → Accepted |
Thanks I confirmed this issue on SQLite and MySQL, it works on PostgreSQL and Oracle.
comment:4 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 4 years ago
Summary: | On MySQL and SQLite, __in lookup doesn't work on key transforms when RHS has a single value. → On MySQL, Oracle, and SQLite, __in lookup doesn't work on key transforms. |
---|
On Oracle, it doesn't work when list contains strings.
comment:6 by , 4 years ago
django-mysql
customizes the __in lookup by encoding the rhs and CAST-ing it to JSON. I think it won't work on MariaDB though, because we can't do casting to JSON. There may be other ways to do it, but I haven't got an idea. Same with SQLite and Oracle.
Thanks for this ticket, however I cannot reproduce this issue. I tried with the following test and it works for me (also on MySQL):
Can you prepare a sample project to reproduce this issue? and provide details about database (specific version, MariaDB/MySQL)?