Fixed #35384 -- Raised FieldError when saving a file without a name to FileField. #18109
+39
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…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.