Allow runserver to bypass model validation
|Reported by:||Brendan Jurd||Owned by:||nobody|
|Component:||Core (Management commands)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I recently encountered a frustrating little issue in one of my apps. I wasn't able to run the development server because of a non-critical model validation failure.
The error was '"ordering" refers to "split_code", a field that doesn't exist.'
In several of my models, "ordering" refers to a field which isn't part of the main model definition, but *is* added to the query set by a custom default Manager. So in practice (when I run it under mod_wsgi) the ordering works exactly as intended. This is a case where the model fails to validate, but actually works properly in a live-fire situation.
Perhaps the model validation is too strict in this case, but I can understand why. It would probably be a lot of fuss to try to make it clever enough to detect additional fields that are pulled in by the queryset on the Manager. But there's a broader issue in that *any* model validation failure, no matter how unimportant, is enough to stop the development server from working with an "Unhandled exception" in 1.3.1.
I think it's fine that I get a message about the "ordering" definition, but I don't think it should be a showstopper.
There are few different ways to get past this. My suggestion would be that when executing "runserver", we should catch CommandErrors coming out of 'validate', report them, and then keep on trying to run the server anyway.
I've included a patch along these lines.
Other options include
- teach 'validate' to recognise fields that are included by the default Manager's queryset,
- teach 'validate' to differentiate between errors that are critical in nature, and those that really only need to be warnings,
- allow SQL expressions in 'ordering', not just field names, so that the custom Manager field isn't necessary in the first place.
... but they all seem like a lot of effort.
Thanks for your time.
Change History (12)
comment:1 follow-up: 2 Changed 4 years ago by
|Patch needs improvement:||unset|
comment:3 Changed 4 years ago by
|Triage Stage:||Unreviewed → Design decision needed|
|Type:||Uncategorized → Bug|
comment:10 Changed 3 years ago by
|Summary:||runserver versus model validation → Allow runserver to bypass model validation|
|Type:||Bug → New feature|
|Version:||1.3 → master|