#33996: Inconsistent behavior of CheckConstraints validation on None values.
-------------------------------------+-------------------------------------
     Reporter:  James Beith          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by David Sanders):

 * cc: David Sanders (added)


Comment:

 Aha I'd also just noticed this behaviour.

 It's due to the check constraint doing the validation in the WHERE clause
 of a query… a NULL value producing an empty resultset hence failing the
 validation:

 {{{
 SELECT 1 AS "_check" WHERE NULL >= 0
 }}}

 The original PR for this feature mentions moving to WHERE from SELECT to
 get around certain issue – which is somewhat unfortunate because using
 SELECT could've given the opportunity to check the result against false.

 My naive suggestion would be to add an |Q(field=None) against nullable
 fields in the check's query.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33996#comment:2>
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/010701831d2b6acd-d4b99d33-d367-4b1c-808e-6fcebf96f013-000000%40eu-central-1.amazonses.com.

Reply via email to