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:

http://dpaste.com/76808/

Attachments (1)

8974.patch (912 bytes ) - added by Samuel Cormier-Iijima 16 years ago.
Simple fix for catching ValueError

Download all attachments as: .zip

Change History (5)

comment:1 by anonymous, 16 years ago

Cc: medoslav@… added

comment:2 by Torsten Bronger <bronger@…>, 16 years ago

Cc: bronger@… added

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.

comment:3 by Thomas Güttler, 16 years ago

The dpaste snippet has expired.

To burp_: Please make the code available again.

by Samuel Cormier-Iijima, 16 years ago

Attachment: 8974.patch added

Simple fix for catching ValueError

comment:4 by Karen Tracey, 16 years ago

Resolution: duplicate
Status: newclosed

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.
Back to Top