{{{
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)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33785>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => duplicate
Comment:
Replying to [ticket:33785 Maksim Iakovlev]:
> {{{
> MyModel.objects.exclude(model_field__json_field__in=['', None])
> }}}
>
> I expect only x3 record in result, but x2 presents too.
This is a duplicate of #20024.
> This is also wrong:
>
> {{{
>
MyModel.objects.exclude(model_field__json_field='').exclude(model_field__json_field__isnull=True)
> }}}
It's [https://docs.djangoproject.com/en/stable/topics/db/queries/#key-
index-and-path-transforms documented] that `__isnull` on key transforms
are using ''"To query for missing keys"'', not to query for a `None`
value.
--
Ticket URL: <https://code.djangoproject.com/ticket/33785#comment:1>