Skip to content

Allow new discipline deletion when it has no users and no collections#7812

Merged
acwhite211 merged 9 commits intomainfrom
issue-7649
Mar 18, 2026
Merged

Allow new discipline deletion when it has no users and no collections#7812
acwhite211 merged 9 commits intomainfrom
issue-7649

Conversation

@acwhite211
Copy link
Member

@acwhite211 acwhite211 commented Mar 13, 2026

Fixes #7649

A newly created discipline could not be deleted from the System Configuration Tool even when it had no user-created records. The delete blocker flow was treating discipline owned tree definition data as blockers, so the UI reported the discipline as undeletable even though the intended business rule is narrower.

This PR adds a special case for disciplines in the delete_blockers API. A discipline can be deleted when it has no associated collections and no associated users. The implementation adds discipline specific guard blockers for collections and users, updates discipline deletion to enforce that rule before delete, and detaches discipline owned tree definitions during the delete flow so preloaded tree data does not create false blockers.

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
  • Add pr to documentation list
  • Add automated tests

Testing instructions

Empty discipline deletion

  • Open the System Configuration Tool as an admin user.
  • Create a new discipline under an existing division.
  • Without creating any collections for that discipline, open the discipline edit form and click Delete.

Verify:

  • The discipline can be deleted successfully.
  • The discipline disappears from the hierarchy/tree UI.
  • GET /delete_blockers/delete_blockers/discipline/<id>/ returns an empty list.

Discipline with collection

  • Create another new discipline and add a collection to it.
  • Attempt to delete that discipline.

Verify:

  • Deletion is blocked.
  • The blocker response/modal includes Collection as the reason.

@acwhite211 acwhite211 added this to the 7.12.1 milestone Mar 13, 2026
@acwhite211 acwhite211 marked this pull request as ready for review March 13, 2026 21:29
@alesan99 alesan99 self-requested a review March 16, 2026 14:14
@acwhite211 acwhite211 requested review from a team March 16, 2026 17:22
@acwhite211
Copy link
Member Author

Looking to see if the discipline deletion process can be made faster.

@acwhite211
Copy link
Member Author

Deleting all the schema config and tree records within the discipline was slowing down the discipline deletion request. One solution was to move the deletion process to the worker, similar to what we do for discipline creation. Another solution was using direct SQL queries, instead of using Django to go through and delete all the dependencies. I went ahead and implemented the direct SQL solution to avoid the complications of a delayed deletion through a worker process.

Copy link
Contributor

@alesan99 alesan99 left a comment

Choose a reason for hiding this comment

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

  • The discipline can be deleted successfully.
  • The discipline disappears from the hierarchy/tree UI.
  • GET /delete_blockers/delete_blockers/discipline/<id>/ returns an empty list.
  • Deletion is blocked.
  • The blocker response/modal includes Collection as the reason.

Disciplines are able to be deleted when expected 👍
I was previously experiencing speed issues, but now deletion happens fast

Image

@alesan99 alesan99 requested a review from a team March 17, 2026 14:32
Copy link
Collaborator

@bhumikaguptaa bhumikaguptaa left a comment

Choose a reason for hiding this comment

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

Verify:

  • The discipline can be deleted successfully.
  • The discipline disappears from the hierarchy/tree UI.
  • GET /delete_blockers/delete_blockers/discipline/<id>/ returns an empty list.

Verify:

  • Deletion is blocked.
  • The blocker response/modal includes Collection as the reason.

Everything looks good, I was able to delete the discipline in the first part and able to verify deletion is blocked.

Image

@CarolineDenis CarolineDenis requested a review from a team March 18, 2026 13:15
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.

  • The discipline can be deleted successfully.
  • The discipline disappears from the hierarchy/tree UI.
  • GET /delete_blockers/delete_blockers/discipline/<id>/ returns an empty list.

Verify:

  • Deletion is blocked.
  • The blocker response/modal includes Collection as the reason.

I did get this error a couple times at the beginning but it would go away after refresh and I am no longer able to recreate so I am assuming it is some test panel issue.

Specify 7 Crash Report - 2026-03-18T17_38_16.846Z.txt

@acwhite211 acwhite211 merged commit a7650d1 into main Mar 18, 2026
14 checks passed
@acwhite211 acwhite211 deleted the issue-7649 branch March 18, 2026 18:09
@github-project-automation github-project-automation bot moved this from 📋Back Log to ✅Done in General Tester Board Mar 18, 2026
@acwhite211 acwhite211 mentioned this pull request Mar 20, 2026
4 tasks
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.

Add tool to delete a newly created discipline without any linked records

5 participants