FileField should not reuse FieldFiles
|Reported by:||Sayane||Owned by:||Andrzej Pragacz|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
A simple example:
old_image = mymodel.image old_image.open() try: mymodel.image = do_something_with_image(old_image) finally: old_image.close() mymodel.save() # transaction manager is in auto commit mode old_image.delete()
New file is commited to disk and database, old file is removed.
New file is commited to disk and database, then this new file is removed from disk.
That's because FileField (or to be more precise: FileDescriptor class) is re-using FieldFile objects instead of creating new FieldFile for every new instance of a file. This leads to unexpected results and data loss (like in example).
Change History (4)
comment:1 Changed 4 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|
comment:2 Changed 12 months ago by
|Owner:||changed from nobody to Andrzej Pragacz|
|Status:||new → assigned|