Skip to content

fix(core): guard post_delete Object audio_description cleanup on None#908

Open
SAY-5 wants to merge 1 commit intomemeLab:developfrom
SAY-5:fix/audio-description-delete-none
Open

fix(core): guard post_delete Object audio_description cleanup on None#908
SAY-5 wants to merge 1 commit intomemeLab:developfrom
SAY-5:fix/audio-description-delete-none

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 18, 2026

Problem

Object.audio_description is declared as
FileField(null=True, blank=True), so an Object created without an
audio description can surface as None in the post_delete signal
receiver. The current code unconditionally dereferences it:

if isinstance(instance, Object):
    instance.source.delete(False)
    instance.audio_description.delete(False)   # AttributeError if None

When that happens, remove_source_file bails out of the cleanup
halfway 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 delete call on the field being truthy. Django's FieldFile
is 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 / Sound branches.

Fixes #849

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

post_delete signal calls audio_description.delete() without None check, causing AttributeError

1 participant