mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #21238 -- Fixed restoring attributes when pickling FileField and ImageField.
This commit is contained in:
committed by
Mariusz Felisiak
parent
aaea9deac4
commit
f600e3fad6
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user