#36722: MySQL backend raises error when selecting 0 using an expression 
targeting
an autofield.
-------------------------------------+-------------------------------------
     Reporter:  Clifford Gama        |                    Owner:  Clifford
                                     |  Gama
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  allows_auto_pk_0     |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Clifford Gama):

 My thinking was that since the validation is save-specific, it should be
 in `get_db_prep_save()`, which is specific to save, instead of
 `get_db_prep_value()` which is also used in filters. I only used `Value(0,
 AutoField())` as a testing strategy for the change, since it helped me
 identify the issue. If it turns out that there's no other use-case where
 filtering zero on an AutoField raises the ValueError, then perhaps this
 ticket would become a cleanup/otimisation instead of a bug.

 For further context:

 The issue discovered in #36689 after I made `ExpressionList` wrap direct
 values of an iterable rhs in `Value()` using an explicit `output_field`
 
([https://github.com/django/django/pull/20009/commits/0c56236dc2b5526044fa326fde8d52ab084b63de
 commit]). The test in the log failed because it has
 `filter=Q(id__in=[F("max_book_author"), 0])`, which, when wrapped in an
 `ExpressionList`, was becoming `ExpressionList(F("max_book_author"),
 Value(0, BigAutoField()))`.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36722#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 visit 
https://groups.google.com/d/msgid/django-updates/0107019a6f6b1d37-0e33f68b-760c-423e-bd19-cc493fd8c95d-000000%40eu-central-1.amazonses.com.

Reply via email to