Ticket #24831: ticket_24831.patch

File ticket_24831.patch, 2.2 KB (added by Andriy Sokolovskiy, 9 years ago)

test to reproduce the issue

  • tests/queryset_pickle/models.py

    diff --git a/tests/queryset_pickle/models.py b/tests/queryset_pickle/models.py
    index 77134a5..0424fdd 100644
    a b class Container(object):  
    6868
    6969class M2MModel(models.Model):
    7070    groups = models.ManyToManyField(Group)
     71
     72
     73class Book(models.Model):
     74    title = models.CharField(max_length=100)
     75
     76
     77class Author(models.Model):
     78    name = models.CharField(max_length=100)
     79    books = models.ManyToManyField(Book, related_name='authors')
     80
     81
     82class Category(models.Model):
     83    title = models.CharField(max_length=100)
     84    books = models.ManyToManyField(Book, related_name='categories')
  • tests/queryset_pickle/tests.py

    diff --git a/tests/queryset_pickle/tests.py b/tests/queryset_pickle/tests.py
    index 5e42d90..15dab75 100644
    a b from django.test import TestCase  
    88from django.utils.encoding import force_text
    99from django.utils.version import get_version
    1010
    11 from .models import Container, Event, Group, Happening, M2MModel
     11from .models import Author, Book, Category, Container, Event, Group, Happening, M2MModel
    1212
    1313
    1414class PickleabilityTestCase(TestCase):
    class PickleabilityTestCase(TestCase):  
    119119        groups = pickle.loads(pickle.dumps(groups))
    120120        self.assertQuerysetEqual(groups, [g], lambda x: x)
    121121
     122    def test_pickle_prefetch_related_with_m2m(self):
     123        author = Author.objects.create(name='John Doe')
     124        book = Book.objects.create(title='Adventures of Doe')
     125        book.authors.add(author)
     126        cat = Category.objects.create(title='Category')
     127        cat.books.add(book)
     128
     129        Category.objects.all().delete()
     130        Author.objects.all().delete()
     131        Book.objects.all().delete()
     132
     133        author = Author.objects.create(name='John Doe')
     134        book = Book.objects.create(title='Adventures of Doe')
     135        book.authors.add(author)
     136        cat = Category.objects.create(title='Category')
     137        cat.books.add(book)
     138
     139        authors = Author.objects.prefetch_related('books__categories').all()
     140        pickle.loads(pickle.dumps(authors))
     141
    122142    def test_missing_django_version_unpickling(self):
    123143        """
    124144        #21430 -- Verifies a warning is raised for querysets that are
Back to Top