Skip to content
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

SIANXKE-380: avoid file deletion before Attachment removal #14

Closed
wants to merge 1 commit into from

Conversation

anx-abruckner
Copy link
Collaborator

This fix prevents the stored file from being deleted prematurely.
The previous version would delete the file even if a following validation (e.g. from another model within an admin form) would fail afterwards - which resulted in the attachment instance still existing in the db, but the referred file being gone (irrevocably).

@christophbuermann
Copy link

@anx-abruckner I don't understand the initial issue.

Using the following setup:

models.py

class TestModel(models.Model):
    name = models.CharField(max_length=50)
    attachments = AttachmentRelation()

admin.py

class TestAttachmentInlineAdmin(BaseAttachmentInlineAdmin):
    show_change_link = True


@admin.register(TestModel)
class TestModelAdmin(admin.ModelAdmin):
    list_display = ("name",)
    inlines = [
        TestAttachmentInlineAdmin,
    ]

If I cause a validation error in the admin change form by leaving the name empty and change the file of the attachment inside the inline, it falsely shows that the attachment is empty (before and after this pull request). After reloading the page (without sending POST data), the attachment is back in its original state and nothing is removed (again before and after this pull request).

The tests that have been modified by this pull request also run without errors, with or without the cleanup_file function that has been removed by this pull request.

@anx-abruckner
Copy link
Collaborator Author

@christophbuermann thank you for checking! The initial issue occurred in a project that copied the package's functionality - I assumed the core issue would also trouble the drf-attacments package, but I failed to reproduce the error. Hence I close this PR until further notice :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants