#25417: Add a system check for an invalid default on a model field
-------------------------------------+-------------------------------------
Reporter: avorio | Owner: charettes
Type: New feature | Status: new
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: decimal, | Triage Stage: Ready for
InvalidOperation, migrations | checkin
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by charettes):
> Validation in Django only happens through forms, and is bypassed when
manipulating a model directly.
That's not true, there's a whole
[https://docs.djangoproject.com/en/1.8/ref/models/instances/#validating-
objects documented layer of model validation].
> The precedent in Django is to allow creation of models that don't
actually validate.
You can still create model instances that don't validate and even save
them if you'd like. The only thing that changed here is that you cannot
tell Django to assign an invalid default value at instantiation time.
> I use fields with `blank=False, default=''` to create a model with empty
content that's only validated when a user edits it through a form.
I'm not entirely sure I understand your use case but wouldn't this special
handling belong at the form level anyway? I think the whole point of the
separation of concerns between the model and the form layer is to be able
to have enough flexibility at this level.
> I don't understand how this is a Django bug at all. The opener of the
bug is doing something wrong with Decimals, and got a
decimal.InvalidOperation error. That seems like what should happen.
The whole point of model field checks is to prevent you from doing the
wrong thing by mistake and confirm you know what you are doing by
silencing false positives.
#25480 is an example where a simple configuration mistake was caught by
this check.
Like Tim said you can silence this check if you want to rely on having a
`blank=False, default=''` field but don't be surprised if something breaks
in Django further down the road.
--
Ticket URL: <https://code.djangoproject.com/ticket/25417#comment:17>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.8253e4d7b28ad7b742071a218d84e05e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.