Opened 16 years ago
Closed 16 years ago
#8974 closed (duplicate)
ModelChoiceField raises "ValueError: invalid literal for int() with base 10: 'abc'" when non-numerical value is supplied
Reported by: | burp_ | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | medoslav@…, bronger@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When I have a Form with a ModelChoiceField, and supply this field with a non-numerical value the specified error occurs on form.is_valid() as it tries to convert 'abc' with int(). The whole thing is reproducible with this code:
Attachments (1)
Change History (5)
comment:1 by , 16 years ago
Cc: | added |
---|
comment:2 by , 16 years ago
Cc: | added |
---|
comment:3 by , 16 years ago
The dpaste snippet has expired.
To burp_: Please make the code available again.
comment:4 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Consolidating dupes of this problem under one ticket, #9209 chosen since that's the one I happened upon first.
Note:
See TracTickets
for help on using tickets.
I can confirm this. Instead of the ValueError, a ValidationError should be raised. In django/forms/models.py, the try blocks in the clean methods of ModelChoiceField and ModelMultipleChoiceField should also catch ValueError exceptions and turn them into ValidationErrors.