Ticket #21238: alternative_patch_ticket_21238.patch

File alternative_patch_ticket_21238.patch, 2.0 KB (added by Vajrasky Kok, 10 years ago)
  • django/db/models/fields/files.py

    diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
    index 08ac441..380f892 100644
    a b class FieldFile(File):  
    129129        if file is not None:
    130130            file.close()
    131131
    132     def __getstate__(self):
    133         # FieldFile needs access to its associated model field and an instance
    134         # it's attached to in order to work properly, but the only necessary
    135         # data to be pickled is the file's name itself. Everything else will
    136         # be restored later, by FileDescriptor below.
    137         return {'name': self.name, 'closed': False, '_committed': True, '_file': None}
    138 
    139132
    140133class FileDescriptor(object):
    141134    """
  • tests/model_fields/test_imagefield.py

    diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py
    index 90b7a65..c07199c 100644
    a b class ImageFieldTests(ImageFieldTestMixin, TestCase):  
    164164
    165165    def test_pickle(self):
    166166        """
    167         Tests that ImageField can be pickled, unpickled, and that the
    168         image of the unpickled version is the same as the original.
     167        Tests that ImageField and ImageFieldFile can be pickled, unpickled,
     168        and that the image of the unpickled version is the same as the original.
    169169        """
    170170        import pickle
    171171
     172        # Pickle the person (ImageField)
    172173        p = Person(name="Joe")
    173174        p.mugshot.save("mug", self.file1)
    174175        dump = pickle.dumps(p)
    class ImageFieldTests(ImageFieldTestMixin, TestCase):  
    179180        loaded_p = pickle.loads(dump)
    180181        self.assertEqual(p.mugshot, loaded_p.mugshot)
    181182
     183        # Pickle the mugshot (ImageFieldFile)
     184        dump = pickle.dumps(p.mugshot)
     185        loaded_mugshot = pickle.loads(dump)
     186        self.assertEqual(p.mugshot.url, loaded_mugshot.url)
     187
    182188
    183189@skipIf(Image is None, "Pillow/PIL is required to test ImageField")
    184190class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
Back to Top