﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31324	Filter JSONField using `=None`	Nikolay Tretyak	Nikolay Tretyak	"{{{
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}}}"	Bug	closed	Database layer (models, ORM)	3.0	Normal	wontfix		Sage Abdullah Alexey Boriskin Simon Charette	Accepted	1	0	0	0	0	0
