diff options
author | Hasan Ramezani <hasan.r67@gmail.com> | 2019-11-10 22:55:48 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-01-09 09:37:59 +0100 |
commit | f600e3fad6e92d9fe1ad8b351dc8446415f24345 (patch) | |
tree | 1f604b9ba4764c936fa95d6ad89d29f98acb1c25 /django/db/models/fields/files.py | |
parent | aaea9deac4dea08ada934a930cfc27765358d8da (diff) | |
download | django-f600e3fad6e92d9fe1ad8b351dc8446415f24345.tar.gz |
Fixed #21238 -- Fixed restoring attributes when pickling FileField and ImageField.
Diffstat (limited to 'django/db/models/fields/files.py')
-rw-r--r-- | django/db/models/fields/files.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index b03d54366a..7ee38d937f 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -123,11 +123,21 @@ class FieldFile(File): file.close() def __getstate__(self): - # FieldFile needs access to its associated model field and an instance - # it's attached to in order to work properly, but the only necessary - # data to be pickled is the file's name itself. Everything else will - # be restored later, by FileDescriptor below. - return {'name': self.name, 'closed': False, '_committed': True, '_file': None} + # FieldFile needs access to its associated model field, an instance and + # the file's name. Everything else will be restored later, by + # FileDescriptor below. + return { + 'name': self.name, + 'closed': False, + '_committed': True, + '_file': None, + 'instance': self.instance, + 'field': self.field, + } + + def __setstate__(self, state): + self.__dict__.update(state) + self.storage = self.field.storage class FileDescriptor: |