Fix Issues with DataProduct Deletion in DeleteView #694
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.
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: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 toform_valid()
.Changes:
DataProductDeleteView.delete()
toform_valid()
to comply with Django'sDeleteView
behavior. This ensures the associated file is actually deleted.data_product.delete()
to remove theDataProduct
reference from the database, resolving theNone
reference issue.This image shows how the filename was changed after deleting and re-adding.
I am using Django 4.2.5