Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#24831 closed Bug (fixed)

Pickling querysets with prefetch_related breaks

Reported by: Lee Semel Owned by: Andriy Sokolovskiy
Component: Database layer (models, ORM) Version: 1.8
Severity: Release blocker Keywords: prefetch_related
Cc: me@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In Django 1.8.1, pickling certain querysets that use prefetch_related breaks, with an error message that pickle can't find the through model, with an error like

    PicklingError: Can't pickle <class 'bug.models.Category_books'>: it's not found as bug.models.Category_books

With these models

from django.db import models

class Book(models.Model):
    title = models.CharField(max_length=100)

class Author(models.Model):
    name = models.CharField(max_length=100)
    books = models.ManyToManyField(Book, related_name='authors')

class Category(models.Model):
    title = models.CharField(max_length=100)
    books = models.ManyToManyField(Book, related_name='categories')

and these tests

from django.test import TestCase
import pickle
from .models import Book, Author, Category

class PickleTestCase(TestCase):
    def setUp(self):
        author1 = Author.objects.create(name='Joe Schmoe')
        author2 = Author.objects.create(name='Jane Schmoe')
        book1 = Book.objects.create(title='Whatever')
        book1.authors.add(author1)
        book1.authors.add(author2)
        book2 = Book.objects.create(title='Another')
        book2.authors.add(author1)
        book2.authors.add(author2)
        cat1 = Category.objects.create(title='Category 1')
        cat1.books.add(book1)
        cat1.books.add(book2)
        cat2 = Category.objects.create(title='Category 2')
        cat2.books.add(book1)
        cat2.books.add(book2)

    def tearDown(self):
        Author.objects.all().delete()
        Book.objects.all().delete()
        Category.objects.all().delete()

    def test_pickle(self):
        qs = Category.objects.prefetch_related('books__authors').all()
        pickle.dumps(qs)

    def test_pickle2(self):
        qs = Author.objects.prefetch_related('books__categories').all()
        pickle.dumps(qs)

    def test_pickle3(self):
        qs = Book.objects.prefetch_related('categories__books').all()
        pickle.dumps(qs)


The second and third tests will fail with the following stack trace

	

	.EE
	======================================================================
	ERROR: test_pickle2 (bug.tests.PickleTestCase)
	----------------------------------------------------------------------
	Traceback (most recent call last):
	  File "/Users/lsemel/www/djangobug/bug/tests.py", line 33, in test_pickle2
	    pickle.dumps(qs)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1374, in dumps
	    Pickler(file, protocol).dump(obj)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
	    self.save(obj)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 600, in save_list
	    self._batch_appends(iter(obj))
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 615, in _batch_appends
	    save(x)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 600, in save_list
	    self._batch_appends(iter(obj))
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 615, in _batch_appends
	    save(x)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 300, in save
	    self.save_global(obj)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global
	    (obj, module, name))
	PicklingError: Can't pickle <class 'bug.models.Category_books'>: it's not found as bug.models.Category_books

	======================================================================
	ERROR: test_pickle3 (bug.tests.PickleTestCase)
	----------------------------------------------------------------------
	Traceback (most recent call last):
	  File "/Users/lsemel/www/djangobug/bug/tests.py", line 37, in test_pickle3
	    pickle.dumps(qs)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1374, in dumps
	    Pickler(file, protocol).dump(obj)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
	    self.save(obj)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 600, in save_list
	    self._batch_appends(iter(obj))
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 615, in _batch_appends
	    save(x)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 600, in save_list
	    self._batch_appends(iter(obj))
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 615, in _batch_appends
	    save(x)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
	    self.save_reduce(obj=obj, *rv)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 419, in save_reduce
	    save(state)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
	    f(self, obj) # Call unbound method with explicit self
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 649, in save_dict
	    self._batch_setitems(obj.iteritems())
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 663, in _batch_setitems
	    save(v)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 300, in save
	    self.save_global(obj)
	  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global
	    (obj, module, name))
	PicklingError: Can't pickle <class 'bug.models.Category_books'>: it's not found as bug.models.Category_books

	----------------------------------------------------------------------
	Ran 3 tests in 0.075s


If the deletions in tearDown() are removed, all the tests pass.

Attachments (1)

ticket_24831.patch (2.2 KB) - added by Andriy Sokolovskiy 5 years ago.
test to reproduce the issue

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by Tim Graham

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Regression in 1.8 bisected to f233bf47dde1d481108142c8d6b4bb3b3d8c6d08.

Changed 5 years ago by Andriy Sokolovskiy

Attachment: ticket_24831.patch added

test to reproduce the issue

comment:3 Changed 5 years ago by Tim Graham

The cause could be similar to #24381 (pickling of some cached_properties that the delete code initializes).

comment:4 Changed 5 years ago by Andriy Sokolovskiy

Has patch: set
Owner: changed from nobody to Andriy Sokolovskiy
Status: newassigned

comment:5 Changed 5 years ago by Tim Graham

Patch needs improvement: set

comment:6 Changed 5 years ago by Andriy Sokolovskiy

Patch needs improvement: unset

comment:7 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 2913d6b7:

Fixed #24831 -- Fixed pickling queryset with prefetch_related() after deleting objects.

comment:8 Changed 5 years ago by Tim Graham <timograham@…>

In 9d83de8f:

[1.8.x] Fixed #24831 -- Fixed pickling queryset with prefetch_related() after deleting objects.

Backport of 2913d6b77d8b2082dc79df5503b7dd3ddd05fcc1 from master

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