#27148 closed Bug (fixed)
Invalid input for UUIDField with ModelMultipleChoiceField throws ValueError, not ValidationError
Reported by: | Daniel Hahler | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have added a test in https://github.com/django/django/pull/7180.
This test shows that an invalid value for a UUIDField will bubble up as
ValueError
. The problem here seems to be that get_prep_value
just
passes through the (invalid) string.
Only when the queryset is evaluated just below via the following code,
the ValueError from UUIDField.get_db_prep_value
is raised and bubbles
up:
self.queryset.filter(**{'%s__in' % key: value}) pks = set(force_text(getattr(o, key)) for o in qs)
Explicitly evaluating the queryset above already would fix it, but that
would get done for every selected value then.
Needs UUIDField
to be fixed for this, e.g. raising the ValueError
from get_prep_value
already?
In this case other fields would need the same fix probably (from what I
have seen while skimming the code).
Attachments (1)
Change History (6)
comment:1 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 8 years ago
Attachment: | 27148.diff added |
---|
Something like the attached might be appropriate.