#25685: Deferred model leak
----------------------------------------------+--------------------
Reporter: ppetrid | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Consider the following models
{{{
from django.db import models
class ModelA(models.Model):
a = models.CharField(max_length=1)
class ModelB(models.Model):
fk = models.ForeignKey(ModelA)
}}}
and the following test
{{{
from django.test import TestCase
from .models import ModelA
class DeferProblemTestCase(TestCase):
def test_defer(self):
a = ModelA.objects.create(a='test')
with self.assertNumQueries(2):
a.delete()
unrelated_qs = list(ModelA.objects.defer('a'))
# lets's try once again
a = ModelA.objects.create(a='test')
with self.assertNumQueries(2):
a.delete()
}}}
The above test fails under django 1.8.6, as the second call to `.delete()`
will produce 3 queries instead of 2. It seems django somehow caches the
deferred model and tries to delete any related ModelB records twice.
Except from the overhead, this can lead to random test fails based on the
execution order.
--
Ticket URL: <https://code.djangoproject.com/ticket/25685>
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/050.8a974d5508d12d2acf33a5931fde46c7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.