#28312: ModelChoiceIterator uses cached length of queryset.
------------------------------------+--------------------------------------
Reporter: Sjoerd Job Postmus | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Comment (by Sjoerd Job Postmus):
Perhaps this can be closed, as (our specific case) is resolved by #27563.
My apologies.
Extra context:
We ran into this problem as our form contained logic as follows:
{{{
if len(self.fields['status'].choices) <= 1:
self.fields.pop('status')
}}}
I tested this: count = 1: no field. Add a `Status`, reload page: still no
field. Turns out the count was being "cached". Since it is a Django 1.8
project, above fix is not taken into account, and the cached value did
indeed live longer than the current request. Looking at the changes, I
expect the behaviour to be correct in Django 2.0.
Even so: the `ModelChoiceIterator` uses `.all()` or `.iterator()` in the
`__iter__` method, and thus forces obtaining a fresh value. But `__len__`
does not do so, and that is an inconsistency that might still qualify as a
bug.
Are there any plans to backport #27563 to Django 1.8? I expect not, as
it's past the "End of mainstream support".
--
Ticket URL: <https://code.djangoproject.com/ticket/28312#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.f321e29552862dac39afe6daad7b3f25%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.