Skip to content

Delete tag updates meilisearch#571

Merged
bradenmacdonald merged 7 commits intoopenedx:mainfrom
mgwozdz-unicon:tag-delete-updates-meilisearch
Apr 29, 2026
Merged

Delete tag updates meilisearch#571
bradenmacdonald merged 7 commits intoopenedx:mainfrom
mgwozdz-unicon:tag-delete-updates-meilisearch

Conversation

@mgwozdz-unicon
Copy link
Copy Markdown
Contributor

@mgwozdz-unicon mgwozdz-unicon commented Apr 29, 2026

Description

This PR in conjunction with the openedx-platform PR (openedx/openedx-platform#38477) is the backend component for openedx/modular-learning#260. This PR ensures that when a tag and its descendants are deleted that CONTENT_OBJECT_ASSOCIATIONS_CHANGED events take place for each associated object with no duplicates. The openedx-platform PR ensures that once those events happen, the entire search document is replaced for the relevant content.

Goal:
When a Course Author deletes a tag that is associated to Library content, they should be able to return to the Library page and not see those tags in the tag search filter.

Supporting information

Github Issue: openedx/modular-learning#260

Testing instructions

Note: This cannot be tested without the code from the following PRs in place:

  1. Go to Taxonomies and select a taxonomy
  2. Add new tags to this taxonomy that you plan to delete. (I have been adding a subtag (e.g. Wind1) with 2 sibbling children (W1.1 and W1.2) for my testing.)
  3. Go to a Library and create 2 new pieces of content.
  4. For one piece of content, associate the parent subtag (e.g. Wind1) and click Save.
  5. For the other piece of content, associate a child (e.g. W1.2) and click Save.
  6. Click on the tag search filter button and note that Wind1 and W1.2 appear in the tag search filter.
  7. Return to the taxonomy and delete the subtag Wind1.
  8. It should disappear from the taxonomy and a toast should display indicating what was deleted.
  9. Go back to the Library and refresh the page in the browser.
  10. The pieces of content you previously associated those tags to should now display that 0 tags are associated to them.
  11. Click on the tag search filter button and note that Wind1 and W1.2 no longer appear in the tag search filter.

Deadline

This is for our Verawood code cut stretch goal.

Other information

While this code requires other PRs in place to be able to test, I believe it can be safely merged without them.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 29, 2026
@openedx-webhooks
Copy link
Copy Markdown

Thanks for the pull request, @mgwozdz-unicon!

This repository is currently maintained by @axim-engineering.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mgwozdz-unicon mgwozdz-unicon force-pushed the tag-delete-updates-meilisearch branch from 0901700 to 2018c05 Compare April 29, 2026 17:19
Comment thread src/openedx_tagging/signal_handlers.py Outdated
Comment thread src/openedx_tagging/signal_handlers.py Outdated
if isinstance(origin, Tag):
return origin.pk == instance.pk

if not isinstance(origin, QuerySet) or origin.model is not Tag:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a runtime error, i.e. should we be raising a TypeError here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. I think we want this to just be a no-op so that an unexpected type doesn't result in aborting or rolling back the delete operation. Let me know if you disagree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If there is no known reason to have gotten into this state, please raise a TypeError here. As far as I can see, this is only being invoked from a place where you're specifically listening to Tag as the sender, so if it's anything other than these two, something is really broken, and it's better to break loudly so that the issue can be found more quickly.

Comment thread src/openedx_tagging/signal_handlers.py Outdated
Comment thread src/openedx_tagging/signal_handlers.py
Comment thread src/openedx_tagging/signal_handlers.py
Comment thread src/openedx_tagging/tasks.py Outdated
Copy link
Copy Markdown
Contributor

@ormsbee ormsbee left a comment

Choose a reason for hiding this comment

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

Handful of questions/requests. Thank you.

mgwozdz-unicon and others added 2 commits April 29, 2026 13:19
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@mgwozdz-unicon mgwozdz-unicon requested a review from ormsbee April 29, 2026 20:46
)
ObjectTag.objects.create(
object_id=delta_object_id,
taxonomy=self.delta.taxonomy,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is confusing when reading this test in isolation, because the tags self.alice and self.delta appear to be coming from two difference taxonomies (self.alice.taxonomy vs. self.delta.taxonomy). I don't think this test belongs in TestTagLineage at all. The 4 or 5 tests related to event emitting should be in a separate test_events.py module.

I won't block the PR on this but I'd strongly prefer to see it at least flagged as a TODO if not moved before merge.

Comment thread tests/openedx_tagging/test_models.py
Comment thread tests/openedx_tagging/test_models.py Outdated
Comment on lines +25 to +26
Descendants deleted via CASCADE are skipped here because the explicit root
tag's handler emits updates for the whole subtree.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious, is there any reason this approach (using _is_explicit_tag_delete, manually emitting events for the descendants, and then suppressing events for the CASCADE) is preferable to just listening for each individual Tag deletion and emitting an event for each one, including the CASCADE deletes (but never manually emitting events for the descendants)?

The latter seems like it would have much simpler code since you wouldn't need this _is_explicit_tag_delete logic. But perhaps it's not as performant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's to prevent duplicate events per object so that it emits one event per object regardless of how many tags in the subtree are applied to it. This does improve performance with N cascade deletes --> N tasks --> N sets of DB queries in the simple approach, versus 1 task with 1 query in the current approach. For large taxonomies this could be significant.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That makes sense, and would be worth mentioning in the code.

Even with that optimization, the number of events emitted could be huge, but since they're in a celery task it should be OK.

@ormsbee ormsbee dismissed their stale review April 29, 2026 22:36

I'm dismissing my review so it doesn't block the merge if Braden gives his approval. I may not be back until much later this evening.

Co-authored-by: Copilot <copilot@github.com>
mgwozdz-unicon and others added 2 commits April 29, 2026 16:21
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@bradenmacdonald bradenmacdonald merged commit 508be7d into openedx:main Apr 29, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Contributions Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants