New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #35384 -- Raised FieldError when saving a file without a name to FileField. #18109
base: main
Are you sure you want to change the base?
Conversation
ed13c1f
to
f5ff4a8
Compare
This will also need a release note 👍 |
Could you provide me with the guide on how to write release note? |
Actually as this is a bug fix, we won't need a release note here. So don't worry 😁 |
👋 @jonnythebard spotted a typo in the PR title, would you mind fixing? |
I added a test for deleting the field filed to check if any error occurs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple smaller improvements. Looking good!
Thanks for the comments🙏 @adamchainz |
bd3224e
to
71e97a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jonnythebard 👍
I've pushed minor updates. I will give the other a chance to make comments on these before I merge
…nce to File field
Trac ticket number
ticket-35384
Branch description
Added code for raising
FieldError
when trying to save ContentFile instance to File field.pre_save
ofFileField
class.pre_save
get's called to save file-like objects, it checks if file is truthy.File
orImageFile
instance, even if they do not have explicit name, name would be retrieved from there actual file. ButContentFile
instance has nowhere to get its name and its name is set toNone
.if file and not file._committed:
) which results inpre_save
method to silently drop it's duty.pre_save
is adequate location to validate ifContentFile.name
because looks like it is responsible for letting the file objects to be passed to file storage manager.if file.name is None:
would affect many other functioning codes.null=True
option will fall into this statement as wellNone
, it is Needed something to represent aContentFile.name
is empty.EmptyName
class and made it default ifContentFile.name
is not passed.pre_save
works fine.Thanks to @john-parton for a good description and isolated tests.
Checklist
main
branch.