#34754: CheckConstraint with isnull lookup on JSONField transform None into null
jsonb value
-------------------------------------+-------------------------------------
     Reporter:  Alexandre Collet     |                    Owner:  Simon
                                     |  Charette
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:  constraint,          |             Triage Stage:  Accepted
  jsonfield, none, check             |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * owner:  nobody => Simon Charette
 * status:  new => assigned
 * has_patch:  0 => 1


Comment:

 Submitted a patch to address the issue but I think the fundamental problem
 here is that

 {{{#!python
 MyModel.objects.create(values=None)  # Creates an object with a SQL NULL
 MyModel.objects.filter(values=None)  # Filters for objects with JSON NULL
 }}}

 This asymmetry prevents logic from being added to
 `JSONField.get_db_prep_value` directly but it's a much larger problem to
 resolve.

 Just like [https://docs.djangoproject.com/en/4.2/ref/models/fields/#null
 we discourage] the usage of `null=True, blank=True` fields as allows for
 the co-existence of two ''no data'' values I think we should do add
 ''friction'' to storing `null` in a `JSONField(null=True)` field by
 requiring that `Value(None, JSONField())` be used to filter using
 `'null'::json`.

 I can't think of a deprecation path for
 `MyModel.objects.filter(values=None)` though unfortunately so it seems
 like we've missed the boat on that one.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34754#comment:4>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070189b8f34afa-e25293e8-849f-4213-9370-cae3bda8bf43-000000%40eu-central-1.amazonses.com.

Reply via email to