Opened 3 years ago
Closed 3 years ago
#33785 closed Bug (duplicate)
Broken __in lookup for keys of json field
| Reported by: | Maksim Iakovlev | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 3.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
For example I have a model with json field:
class MyModel():
model_field = JsonField()
I create 3 records in db:
x1 = MyModel(model_field={json_field=''}).save()
x2 = MyModel(model_field={json_field=None}).save()
x3 = MyModel(model_field={json_field='foobar'}).save()
And then I want for filter all records which contains non-empty json_field like this:
MyModel.objects.exclude(model_field__json_field__in=['', None])
I expect only x3 record in result, but x2 presents too. This is also wrong:
MyModel.objects.exclude(model_field__json_field='').exclude(model_field__json_field__isnull=True)
Only this filter works as expected:
MyModel.objects.exclude(model_field__json_field='').exclude(model_field__json_field=None)
Note:
See TracTickets
for help on using tickets.
Replying to Maksim Iakovlev:
This is a duplicate of #20024.
It's documented that
__isnullon key transforms are using "To query for missing keys", not to query for aNonevalue.