Opened 10 years ago

Closed 10 years ago

#23095 closed Bug (invalid)

clean of ModelMultipleChoiceField tries to return EmptyQuerySet

Reported by: pedro.celes123@… Owned by: nobody
Component: Forms Version: 1.6
Severity: Normal Keywords: forms validation ModelMultipleChoiceField queryset.none()
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the clean method of the class ModelMultipleChoiceField if the value of the field is not and the field is not required the method will return:

return self.queryset.none()
# In my version (1.6.5, final) this is on line 1180 of file django/forms/models.py

However in the release notes it is stated: "The django.db.models.query.EmptyQuerySet can’t be instantiated any more - it is only usable as a marker class for checking if none() has been called: isinstance(qs.none(), EmptyQuerySet)"

So if I have a form which contains a ModelMultipleChoiceField which is not required and no value is attached to it, in the validation process (more specifically in the clean of said field) the following error will be raised:

TypeError: EmptyQuerySet can't be instantiated

Change History (3)

comment:1 by Tim Graham, 10 years ago

I'm having a little trouble understanding how to trigger this error. Could you write a test case for Django's test suite that demonstrates it?

comment:2 by pedro.celes123@…, 10 years ago

Sorry for the inconvenience, due to a monkey patch used in my company I was fooled to think the problem was with django. After more thorough tests we discovered the problem was with us.
Really sorry.

comment:3 by Tim Graham, 10 years ago

Resolution: invalid
Status: newclosed

No problem, thanks for following up.

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