#12285 closed (fixed)
Confusing error message when ModelForm does not have model set
| Reported by: | Erik Allik | Owned by: | Karen Tracey |
|---|---|---|---|
| Component: | Forms | Version: | 1.1 |
| Severity: | Keywords: | ||
| Cc: | brian@… | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | UI/UX: |
Description
When instantiating a ModelForm whose Meta.model has not been set (i.e. the ModelForm class was extended instead of Form), the exception message is:
'NoneType' object is not callable
This message originates from django/forms/models.py in __init__ line 218 that says self.instance = opts.model().
Adding an if there with a decent message such as "Model class not set for ModelForm" would be the fix.
Attachments (2)
Change History (13)
by , 16 years ago
| Attachment: | 12285.diff added |
|---|
comment:1 by , 16 years ago
| Has patch: | set |
|---|
comment:2 by , 16 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 16 years ago
| Owner: | changed from to |
|---|---|
| Status: | assigned → new |
| Triage Stage: | Unreviewed → Accepted |
Works as intended. My personal preference is for unit tests, but that might just be me. Also the exception could be made more specific (AttributeError? ValueError?).
Otherwise, this seems like a simple, intuitive fix to an obscure error.
comment:4 by , 16 years ago
| Owner: | changed from to |
|---|
I have a slight preference for the unittest/ValueError way but I'm not sure which patch makes the most sense in the bigger scheme of things
comment:5 by , 16 years ago
| Cc: | added |
|---|
comment:6 by , 16 years ago
I think 12285.diff is good. Applied it and it works fine.
The module already raises Exception errors on a bunch of other things and the tests are already a doctest.
Raising Exception is IMHO a bad practice since it's not very explicit. A custom defined error would be much better.
by , 16 years ago
| Attachment: | 12285-unit-test-ValueError.diff added |
|---|
updated patch uses 'is None' and applies against trunk
comment:9 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
reviewing patch