core.files.File assumes name attribute on file-like objects
|Reported by:||PaulM||Owned by:||charettes|
|Cc:||charette.s@…, nickname123||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||yes|
The django.core.files.File object is a wrapper to add some django-specific stuff around standard python file-like objects.
In the __init__ and elsewhere, File works around file-like objects which may not have a name attribute (optional for python file objects). However, down in the _size() getter, it slips up and makes the assumption that the file-like object has a name attribute. This means that it produces a confusing attribute error about name rather than the desired error about being unable to determine a file's size.
This should be patched to check for self.name before doing the os.path.exists, like line 113.
Change History (10)
Changed 4 years ago by charettes
comment:2 Changed 4 years ago by PaulM
- Component changed from Uncategorized to Core (Other)
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Uncategorized to Bug
comment:4 Changed 4 years ago by charettes
- Owner changed from nobody to charettes
- Status changed from new to assigned