Opened 4 years ago
Closed 4 years ago
#32078 closed Uncategorized (worksforme)
Inconsistent JSONField filtering for value None
Reported by: | fre-db | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.1 |
Severity: | Normal | Keywords: | JSONField, None |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When a JSONField has a key with Value None
, only filtering on __key__in=[None]
works, while you'd expect you could also just filter on __key=None
or __key__isnull=True
.
Example below:
import django print(django.__version__) 3.1.2 print(Model.objects.get(pk=99657).jsonfield) {'key': None} print(Model.objects.filter(jsonfield__key=None).filter(pk=99657).count()) 0 print(Model.objects.filter(jsonfield__key__is_null=True).filter(pk=99657).count()) 0 print(Model.objects.filter((jsonfield__key__in=[None]).filter(pk=99657).count()) 1
Note:
See TracTickets
for help on using tickets.
It works as expected for me:
See Storing and querying for None and Key, index, and path transforms docs.