fix: Handle Taxonomy CASCADE deletes in _is_explicit_tag_delete#575
Merged
kdmccormick merged 1 commit intomainfrom Apr 30, 2026
Merged
fix: Handle Taxonomy CASCADE deletes in _is_explicit_tag_delete#575kdmccormick merged 1 commit intomainfrom
kdmccormick merged 1 commit intomainfrom
Conversation
758d08c to
bc2b795
Compare
When a Taxonomy is deleted, Django fires pre_delete for each related Tag with origin set to the Taxonomy instance. The previous code raised a TypeError for any non-Tag, non-QuerySet origin, breaking any consumer that deletes a Taxonomy. For a non-Tag-queryset origin (e.g. taxonomy.delete() or Taxonomy.objects.filter(...).delete()), we now emit only for root-level tags; their handler covers the whole subtree via lineage__startswith. Bumps to v1.0.1. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
bc2b795 to
8fd7193
Compare
This was referenced Apr 30, 2026
ormsbee
previously approved these changes
Apr 30, 2026
Contributor
ormsbee
left a comment
There was a problem hiding this comment.
This seems fine to me, and I would prefer to fix forward.
Need to check my assumptions about how taxonomy deletes are already handled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Merge info
For Verawood, we need to merge either this PR, or just the straightforward revert: #577. Both are ready to go.
EDIT: #576 is also a potential fix.
Description
When a Taxonomy is deleted, Django fires pre_delete for each related Tag with origin set to the Taxonomy instance. The previous code raised a TypeError for any non-Tag, non-QuerySet origin, breaking any consumer that deletes a Taxonomy.
For a non-Tag-queryset origin (e.g. taxonomy.delete() or Taxonomy.objects.filter(...).delete()), we now emit only for root-level tags; their handler covers the whole subtree via lineage__startswith.
Bumps to v1.0.1.
Supporting information
The original code was added in #571
while upgrading to v1.0, openedx-platform unit tests caught this:
https://gist.github.com/kdmccormick/912e71d4a57bf8aed046e9be3ca297e7
AI
Generated by Claude Sonnet 4.6 with my prompt:
which it got right on the first try. I just had a couple follow-ups to tweak its coding style.
I then had Opus 4.7 audit the change, and it suggested the additional test_taxonomy_delete_updates_search_index test.
I reviewed all code myself.