Opened 7 months ago
Closed 6 months ago
#35384 closed Bug (fixed)
Assigning a file without a name property to a FileField results in file getting discarded silently
Reported by: | john-parton | Owned by: | Jonny Park |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.0 |
Severity: | Normal | Keywords: | |
Cc: | Lily Foote | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you assign a File object without a name (A ContentFile or otherwise) to an instance and then save it, the storage backend is not invoked, the data isn't persisted, and the column isn't updated. All without raising an error or even a logger message.
We've isolated the behavior here: https://github.com/john-parton/django-file-field-no-name/blob/dc557c641552b02623f50ef044d73435b9e97ead/test_app/tests.py#L28-L41
There's some discussion here: https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192/24
The general consensus is that some error should be raised.
I'll see if I can submit a patch. I flagged this as Database layer, because the patch will likely be in models.files, not the storage backend.
Change History (9)
comment:1 by , 7 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 7 months ago
Cc: | added |
---|
comment:3 by , 7 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 7 months ago
Has patch: | set |
---|
comment:5 by , 7 months ago
The patch will still not pass test_can_reread_content_file
at https://github.com/john-parton/django-file-field-no-name/blob/dc557c641552b02623f50ef044d73435b9e97ead/test_app/tests.py#L74-L83
I think it deserves it's own ticket and disccusion.
comment:6 by , 7 months ago
Patch needs improvement: | set |
---|
comment:7 by , 6 months ago
Patch needs improvement: | unset |
---|
comment:8 by , 6 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Thank you for the analysis and discussions 👍