Skip to content

Conversation

@acwhite211
Copy link
Member

@acwhite211 acwhite211 commented Jun 20, 2024

Fixes #5021

The issue was that the specify models.py file was generated after the add_deete_ranks PR was merged. So the on_delete=models.DO_NOTHING wasn't applied in the re-definition.

Old:
Add a filter to delete_blockers, so that blockers that aren't really actually blockers and filtered out. This will fix the delete_blockers issue we are having with deleting tree ranks. Delete a Taxontreedefitem should only be blocked by a Taxon, not another Taxontreedefitem, this dependency is handled in the api call for tree rank deletion. Let me know if someone has a better idea, this just seemed like a simple solution. Is there a case where we would want these blockers not to be filtered?

Checklist

  • Self-review the PR after opening it to make sure the changes look good
    and self-explanatory (or properly documented)
  • Add relevant issue to release milestone

Testing instructions

  1. Go to any tree
  2. Add a new rank by pressing the pencil button, then the plus button, select the parent, press continue, fill out fields, press save, wait for the page to reload.
  3. Select any parent node that is not the last one when adding a new rank.
  4. Try to delete the rank by pressing the pencil button, then press the pencil button next to your test rank, then press delete, confirm delete, wait for the page to reload.
  5. Make sure there is no error, and that the tree rank is no longer there

#5021 (comment)

Copy link
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

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

Testing instructions

  1. Go to any tree
  2. Add a new rank
  3. Select any parent node that is not the last one
  4. Try to delete the rank
  5. Make sure there is no error, and that the tree rank is no longer there

#5021 (comment)


Works for taxon and geography trees but there's still a deletion blocker when trying to delete a storage tree rank
Screenshot 2024-06-20 132434

@acwhite211 acwhite211 changed the title Add DELETE_BLOCKER_EXCEPTIONS Filter Add DO_NOTHING for on_delete on TreeDefItems Jun 20, 2024
@acwhite211 acwhite211 requested a review from emenslin June 20, 2024 18:45
@acwhite211
Copy link
Member Author

acwhite211 commented Jun 20, 2024

The issue was that the specify models.py file was generated after the add_delete_ranks PR was merged. So the on_delete=models.DO_NOTHING wasn't applied in the re-definition.

Copy link
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

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

Testing instructions

  1. Go to any tree
  2. Add a new rank by pressing the pencil button, then the plus button, select the parent, press continue, fill out fields, press save, wait for the page to reload.
  3. Select any parent node that is not the last one when adding a new rank.
  4. Try to delete the rank by pressing the pencil button, then press the pencil button next to your test rank, then press delete, confirm delete, wait for the page to reload.
  • Make sure there is no error, and that the tree rank is no longer there

#5021 (comment)

Looks good, can delete tree ranks in all trees!

Copy link
Contributor

@Areyes42 Areyes42 left a comment

Choose a reason for hiding this comment

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

Testing instructions

  1. Go to any tree
  2. Add a new rank by pressing the pencil button, then the plus button, select the parent, press continue, fill out fields, press save, wait for the page to reload.
  3. Select any parent node that is not the last one when adding a new rank.
  4. Try to delete the rank by pressing the pencil button, then press the pencil button next to your test rank, then press delete, confirm delete, wait for the page to reload.
  • Make sure there is no error, and that the tree rank is no longer there

Seems to fix it on all trees now 👍

Copy link
Contributor

@melton-jason melton-jason left a comment

Choose a reason for hiding this comment

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

Nice!

I checked the other special deletion rules as well and they are now consistent with the Model definitions

SPECIAL_DELETION_RULES = {
'Agent.specifyuser': models.SET_NULL,
'Recordsetitem.recordset': models.CASCADE,
# Handle workbench deletion using raw sql in business rules.
'Workbenchrow.workbench': models.DO_NOTHING,
'Workbenchdataitem.workbenchrow': models.DO_NOTHING,
'Workbenchrowimage.workbenchrow': models.DO_NOTHING,
'Workbenchrowexportedrelationship.workbenchrow': models.DO_NOTHING,
'Spappresourcedir.specifyuser': models.CASCADE,
'Spappresource.specifyuser': models.CASCADE,
'Spappresource.spappresourcedir': models.CASCADE,
'Spappresourcedata.spappresource': models.CASCADE,
'Spappresourcedata.spviewsetobj': models.CASCADE,
'Spreport.appresource': models.CASCADE,
'Geographytreedefitem.parent': models.DO_NOTHING,
'Geologictimeperiodtreedefitem.parent': models.DO_NOTHING,
'Lithostrattreedefitem.parent': models.DO_NOTHING,
'Storagetreedefitem.parent': models.DO_NOTHING,
'Taxontreedefitem.parent': models.DO_NOTHING,
}


Not related to this PR, but I also noticed some unused code from #4257 and thought I'd mention it here so there's more of a paper trail.

tables_with_pre_constraints_delete = [
# 'Geographytreedefitem',
# 'Geologictimeperiodtreedefitem',
# 'Lithostrattreedefitem',
# 'Storagetreedefitem',
# 'Taxontreedefitem',
]

if table.django_name in tables_with_pre_constraints_delete:
attrs['pre_constraints_delete'] = pre_constraints_delete

Code that functionally does nothing currently could lead other developers (or yourself in the future!) to look into this red herring.
Could this be either removed or commented?
At the very least a comment explaining the envisioned use for this code would go a long way!

Copy link
Contributor

@realVinayak realVinayak left a comment

Choose a reason for hiding this comment

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

Looking good!

@acwhite211
Copy link
Member Author

@melton-jason thanks, I checked that all the special cases are represented in the models.py file. the specify models.py file was generated after the add_delete_ranks PR was merged, so it was the only one not to get their on_delete function set correctly. I added a comment for pre_constraints_delete.

@acwhite211 acwhite211 merged commit c62b400 into production Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Cannot delete tree ranks

8 participants