is_valid() with null field value on ModelForms from models with non-nullable ForeignKeys causes ValueError
|Reported by:||Peter Bengtsson||Owned by:||ANUBHAV JOSHI|
|Cc:||Roman Barczyński, Mjumbe Poe, anubhav9042@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
See this email for a longer description and a traceback.
If you try to use a ModelForm to create a form without the intention of running the
save() method it will raise a ValueError when you call
is_valid(). This is because the ForeignKey field has a setattr override which prevents it from being None at all, ever. When you're just testing the form it should wrap this in a case so that it doesn't immediately complain.
Change History (24)
comment:3 Changed 7 years ago by
|Summary:||is_valid() on ModelForms on models with ForeignKeys cause ValueError rather than False → is_valid() with null field value on ModelForms from models with non-nullable ForeignKeys causes ValueError|
|Triage Stage:||Accepted → Design decision needed|