#31324: Filter JSONField using `=None` -------------------------------------+------------------------------------- Reporter: Nikolay Tretyak | Owner: Nikolay | Tretyak Type: Bug | Status: assigned Component: Database layer | Version: 3.0 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Carlton Gibson): There's definitely room for a docs clarification of the exact behaviour here, but I think the current behaviour is correct/desired. I think it was a deliberate change in behavior, rather than a regression. ([https://docs.djangoproject.com/en/3.0/releases/2.1/#miscellaneous It was documented as a backwards incompatible change].) #25718 came up because people using JSONField are wanting to query for the (JSON) `null` in the vast majority of cases. (99%? 99.9%? ...) For most occurrences, checking for (SQL) `NULL` is the wrong behaviour. We also want(ed) the same behaviour for checking the base field for `null` (`field=None`) as a nested key (`field__a__b__c=None`). This is so much more helpful for users of JSONField, that the weirdness is a cost worth paying. (Better docs, always.) (The ambiguity around querying for `null` vs `NULL` is something that previously I've seen come up repeatedly on DRF and django-filter.) > So, to update the Django version in my project I have to migrate all NULL values to 'null'? I'm almost tempted towards "Yes" for that. Much in the same way as the empty value for `CharField` is `''`, the empty string, rather that `None` for JSONField, you don't really/often want to be writing `NULL` — the empty value for JSON is `null`. I wonder if (without an explicit `null=True`) `JSONModel(field=None)` should write the JSON value `null`, rather than have to do `JSONModel(field=Value('null'))`. In, general, on this last, I think having users need to use `Value` for the default use-case is not optimal. -- Ticket URL: <https://code.djangoproject.com/ticket/31324#comment:10> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.4dd4302b72f012aae75330afb83f9c95%40djangoproject.com.