fix(core): guard post_delete Object audio_description cleanup on None#908
Open
SAY-5 wants to merge 1 commit intomemeLab:developfrom
Open
fix(core): guard post_delete Object audio_description cleanup on None#908SAY-5 wants to merge 1 commit intomemeLab:developfrom
SAY-5 wants to merge 1 commit intomemeLab:developfrom
Conversation
Object.audio_description is FileField(null=True, blank=True), so an Object created without one can surface as None in the post_delete signal receiver. The previous unconditional instance.audio_description.delete(False) then raises AttributeError and aborts the rest of remove_source_file, leaving the just-removed source file orphaned on disk with no matching database row. Gate the call on the field being truthy so we keep cleaning up when there is no audio description attached. Fixes memeLab#849 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Object.audio_descriptionis declared asFileField(null=True, blank=True), so anObjectcreated without anaudio description can surface as
Nonein thepost_deletesignalreceiver. The current code unconditionally dereferences it:
When that happens,
remove_source_filebails out of the cleanuphalfway through. The source file we just removed ends up orphaned on
disk with no matching row, which is exactly the state the signal
receiver is there to prevent. See #849.
Fix
Gate the
deletecall on the field being truthy. Django'sFieldFileis already truthy only when a file is associated, so this also covers
the "empty
FieldFile" case cleanly.if isinstance(instance, Object): instance.source.delete(False) - instance.audio_description.delete(False) + if instance.audio_description: + instance.audio_description.delete(False)No change to the happy path or to the
Marker/Soundbranches.Fixes #849