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

Fix Issues with DataProduct Deletion in DeleteView #694

Merged
merged 2 commits into from
Oct 3, 2023

Conversation

davner
Copy link
Contributor

@davner davner commented Oct 2, 2023

This pull request addresses two issues related to the deletion of DataProduct objects. The first issue was that the files were not being properly deleted, causing name collisions for newly added files. This is in context of when adding previous observational data by obs ID.

In the previous version, deleting a DataProduct was being ignored because:

DeleteView uses FormMixin to handle POST requests. 
As a consequence, any custom deletion logic in DataProductDeleteView.delete() handler 
should be moved to form_valid().

This problem was noticed when a random string was being appended to filenames, due to collisions caused by the delete() method being ignored, after being deleted and re-added. Django appends such a string to avoid filename collision when the file is not actually deleted.

The second issue was that the DataProduct reference was not being removed, leading to errors in subsequent calls to creating data product context. This was only realized after moving to form_valid().

Changes:

  • Moved the deletion logic from DataProductDeleteView.delete() to form_valid() to comply with Django's DeleteView behavior. This ensures the associated file is actually deleted.
  • Added a call to data_product.delete() to remove the DataProduct reference from the database, resolving the None reference issue.

This image shows how the filename was changed after deleting and re-adding.
Pasted image 20231002085627

I am using Django 4.2.5

@jchate6 jchate6 added the bug Something isn't working label Oct 3, 2023
@jchate6 jchate6 self-requested a review October 3, 2023 16:51
@jchate6
Copy link
Contributor

jchate6 commented Oct 3, 2023

Straight from the Django 4.0 Documentation

Copy link
Contributor

@jchate6 jchate6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most beautiful PR I've seen in ages.
Thanks for this.

@jchate6 jchate6 merged commit 82891fa into TOMToolkit:dev Oct 3, 2023
10 checks passed
@davner davner deleted the fix/dataproduct-delete branch October 27, 2023 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants