#27159: Pickling query from queryset causes unintended queryset evaluation
-------------------------------+--------------------
Reporter: jtiai | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
According to documentation pickling queryset.query should be correct
approach and it should only pickle only relevant information to recreate
queryset.query again.
Given models:
{{{#!python
from django.db import models
# Create your models here.
class ParentModel(models.Model):
name = models.CharField(max_length=64)
class ChildModel(models.Model):
name = models.CharField(max_length=64)
parent = models.ForeignKey('ParentModel', related_name='children')
}}}
Following querys, when pickled causes unwanted evaluation and creating
quite large pickled result:
{{{#!python
for x in range(1,10000):
ParentModel(name='Parent {}'.format(x), ).save()
ChildModel(name='Child 1', parent=ParentModel.objects.all()[0]).save()
parents_1 = ParentModel.objects.all().values_list('pk', flat=True)
children_1 = ChildModel.objects.filter(parent__in=parents_1)
pickled_stuff_1 = pickle.dumps(children_1.query)
parents_2 = ParentModel.objects.all()
children_2 = ChildModel.objects.filter(parent__in=parents_2)
pickled_stuff_2 = pickle.dumps(children_2.query)
# First len is about 74 kilobytes, second len is about 2 megabytes.
print len(pickled_stuff_1), len(pickled_stuff_2)
}}}
When comparing sizes of pickled queries both are relatively big. When
inspecting latter pickle it can be seen that it actually contains all
instances from fully evaluated queryset. Same behavior exists in 1.8 and
1.10 as well.
--
Ticket URL: <https://code.djangoproject.com/ticket/27159>
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/048.615f08cc18de6c10258891003acffa04%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.