Opened 13 days ago
Last modified 2 days ago
#35384 assigned Bug
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: | Accepted |
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 (5)
comment:1 by , 12 days ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 12 days ago
Cc: | added |
---|
comment:3 by , 6 days ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 3 days ago
Has patch: | set |
---|
comment:5 by , 2 days 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.
Thank you for the analysis and discussions 👍