Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#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)

27148.diff (1.1 KB ) - added by Tim Graham 8 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

Something like the attached might be appropriate.

by Tim Graham, 8 years ago

Attachment: 27148.diff added

comment:2 by Tim Graham, 8 years ago

Has patch: set

comment:3 by GitHub <noreply@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 2f9861d8:

Fixed #27148 -- Fixed ModelMultipleChoiceField crash with invalid UUID.

comment:4 by Tim Graham <timograham@…>, 7 years ago

In d264131:

Refs #27148 -- Fixed UUIDField.to_python(None) crash.

Regression in 2f9861d823620da7ecb291a8f005f53da12b1e89.

comment:5 by Tim Graham <timograham@…>, 7 years ago

In 4101b57:

[1.11.x] Refs #27148 -- Fixed UUIDField.to_python(None) crash.

Regression in 2f9861d823620da7ecb291a8f005f53da12b1e89.

Backport of d26413113c1a5c95218fe4e43a684a2fe1ad1bff from master

Note: See TracTickets for help on using tickets.
Back to Top