#31324: Filter JSONField using `=None`
-------------------------------------------+------------------------
               Reporter:  Nikolay Tretyak  |          Owner:  nobody
                   Type:  Bug              |         Status:  new
              Component:  Uncategorized    |        Version:  2.2
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 {{{
 from django.contrib.postgres.fields import JSONField
 from django.db import models

 class A(models.Model):
     field = JSONField(null=True)

     class Meta:
         app_label = 'T'

 print(A.objects.filter(field=None).query)  # SELECT "T_a"."id",
 "T_a"."field" FROM "T_a" WHERE "T_a"."field" = 'null'

 print(A.objects.filter(field__isnull=True).query)  # SELECT "T_a"."id",
 "T_a"."field" FROM "T_a" WHERE "T_a"."field" IS NULL
 }}}

 If I create a new object with {{{A.objects.create(field=None)}}}, it will
 be stored in the database as NULL. Therefore, I think it would be better
 to use {{{IS NULL}}} query in the first filter from the example. And it
 worked like this at least in 1.9

 Moreover, with the behavior that we have now I can't even do
 {{{A.objects.filter(field=existing_obj.field)}}} if {{{existing_obj.field
 is None}}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31324>
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/052.d139de81cf517982e609e225384a588b%40djangoproject.com.

Reply via email to