#27937: Potential issue with field.queryset._result_cache persisting
-----------------------------------------+------------------------
Reporter: Luke Benstead | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hi,
I'm currently working on porting Djangae to work with Django 1.11. As part
of our test suite we run a number of Django tests which occasionally show
up assumptions in the tests which don't hold true on the Google App Engine
datastore, one common one is that IDs of objects created in tests will be
sequential.
The last remaining test failure I have is a sporadic failure in
`tests.model_forms.tests.LimitChoicesToTests` depending on the order in
which the tests are run, either
`test_limit_choices_to_callable_for_fk_rel` or
`test_limit_choices_to_callable_for_m2m_rel` fails.
Here's one of those tests:
def test_limit_choices_to_callable_for_fk_rel(self):
"""
A ForeignKey can use limit_choices_to as a callable (#2554).
"""
stumpjokeform = StumpJokeForm()
self.assertSequenceEqual(stumpjokeform.fields['most_recently_fooled'].queryset,
[self.threepwood])
The reason for the failure, is that immediately after `StumpJokeForm()` is
instantiated (by the second of the two tests) the field's
`queryset._result_cache` is already populated, holding an instance which
no longer exists in the database as it was flushed between tests. It's as
if the field's queryset is persisting between form instantiations, and
between tests. It looks likely that this wouldn't show up in a normal
Django test run because IDs are sequential there and so the IDs match when
testing the assertion.
I'm always unsure about reporting bugs like this because Djangae has to do
so much "weird" stuff to work it's possible it's something that we're
doing but in this case I don't think it is. If it is something we're doing
then I apologise in advance :)
--
Ticket URL: <https://code.djangoproject.com/ticket/27937>
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/049.520c043421d199838acf405a7bafff00%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.