Opened 8 months ago

Closed 7 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 Sarah Boyce, 8 months ago

Triage Stage: UnreviewedAccepted

Thank you for the analysis and discussions 👍

comment:2 by Lily Foote, 8 months ago

Cc: Lily Foote added

comment:3 by Jonny Park, 8 months ago

Owner: changed from nobody to Jonny Park
Status: newassigned

comment:4 by Jonny Park, 8 months ago

Has patch: set

comment:5 by Jonny Park, 8 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 Sarah Boyce, 8 months ago

Patch needs improvement: set

comment:7 by Sarah Boyce, 7 months ago

Patch needs improvement: unset

comment:8 by Sarah Boyce, 7 months ago

Triage Stage: AcceptedReady for checkin

comment:9 by Sarah Boyce <42296566+sarahboyce@…>, 7 months ago

Resolution: fixed
Status: assignedclosed

In c0b0ce8:

Fixed #35384 -- Raised FieldError when saving a file without a name to FileField.

Note: See TracTickets for help on using tickets.
Back to Top