#35223: Fields with db_default raise ValidationErrors when full_clean() called
-------------------------------------+-------------------------------------
     Reporter:  Brian Ibbotson       |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

 I believe that we should find a way to have `db_default` behave the same
 way as generated fields when no value has been assigned to the instance
 when `full_clean` is called (#35127). Requiring users to explicitly pass
 it to `exclude` is simply bad ergonomics IMO.

 One thing that the solution should take into account is that the value
 should only be skipped when the value is not assigned. In other words

 {{{#!python
 class Article(models.Model):
    upvotes = models.PositiveIntegerField(db_default=0)

 a1 = Article(upvotes=-1)
 a1.full_clean()  # should raise a ValidationError

 a2 = Article(upvotes=42)
 a2.full_clean()  # should *not* raise a ValidationError

 a1 = Article()
 a1.full_clean()  # should not raise a ValidationError
 }}}

 In other words, when a value is present it should be validated otherwise
 if `db_default` is provided it should be assumed to be valid just like
 it's the case with generated fields.

 A workaround in the mean time is to have both `default` and `db_default`
 assigned but obviously that kind of defeats the purpose of using
 `db_default` in the first place.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35223#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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018db3cd7f7b-4071fe8d-6aa8-454d-9e69-5fb99e577da8-000000%40eu-central-1.amazonses.com.

Reply via email to