Deleting a tag or taxonomy emits search-index events for objects tagged in other taxonomies
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 79/100
Research direction
Start with tag_pre_delete in src/openedx_tagging/signal_handlers.py and compare its query with the taxonomy-scoped lineage queries mentioned in api.py and models/base.py. Add a regression test in tests/openedx_tagging/test_models.py using two taxonomies with the same root tag value. Done means deleting the unused taxonomy emits no event for the object tagged only in the other taxonomy, while existing delete behavior remains covered.
Written by the indexing model from the issue text.
Description
Summary
When a tag is deleted, tag_pre_delete in src/openedx_tagging/signal_handlers.py collects the objects whose search documents need refreshing with ObjectTag.objects.filter(tag__lineage__startswith=instance.lineage). A tag's lineage is the tab-separated chain of tag values from the root to the tag, and it carries no taxonomy. The filter therefore matches every object tagged with a tag of the same value path in any taxonomy, not just the taxonomy being changed. Deleting a whole taxonomy runs the same filter for each of its root tags.
The handler was added in https://github.com/openedx/openedx-core/pull/571 for https://github.com/openedx/modular-learning/issues/260, and https://github.com/openedx/openedx-core/pull/575 extended it to taxonomy deletes. The unscoped filter is on main and in the 1.0.x releases.
The cross-taxonomy match does not look intended. The description of https://github.com/openedx/openedx-core/pull/571 speaks of "a tag and its descendants", and the code comments say the root tag's handler "covers the whole subtree". The event spec in https://github.com/openedx/openedx-core/issues/557 asks for events for "every object tagged using that particular tag" on a tag delete and "every object that had been tagged using that taxonomy" on a taxonomy delete. The tests in tests/openedx_tagging/test_models.py use a single taxonomy, so none of them covers the case. Neither PR's review discussed matching across taxonomies.
Steps to reproduce
- In Studio, create taxonomy A with a root tag
Math, make it available to an organization, and applyMathto a library component or a course unit of that organization. - Create taxonomy B with a root tag
Math. Don't apply it to anything. - Delete taxonomy B.
- Check the CMS log.
Expected result
Taxonomy B has no object tags, so deleting it emits no CONTENT_OBJECT_ASSOCIATIONS_CHANGED events and logs nothing about associated objects.
Actual result
Following the handler code, CMS logs Deleted tag(s) affected 1 associated objects. Emitted CONTENT_OBJECT_ASSOCIATIONS_CHANGED events. The object tagged in taxonomy A gets an event and its search document is rebuilt, although none of its tags changed. The same happens when only the tag Math is deleted from taxonomy B rather than the whole taxonomy.
The search data stays correct, because the platform handler rebuilds the document from the object's current tags. The cost is extra work: one event and one index update per matching object, for every delete.
Measured on a local Tutor dev stack (openedx-core 7e150e7), where Celery runs eagerly so the events are emitted inside the request: deleting a taxonomy with no object tags of its own, whose root tag value matched 60 objects tagged in other taxonomies, returned 204 after 18.8 s. After those 60 object tags were removed, the same delete took 0.15 s. On an install with Celery workers the request itself stays fast, and the extra events go to the workers instead.
Impact
Tag values like Math, Beginner or Python are common across taxonomies, and taxonomies are often created by copying or re-importing an existing one. On such an install, deleting one tag or one unused taxonomy queues index updates for every object tagged with the same value in any other taxonomy, potentially thousands. Installs without Celery workers, such as development stacks, can hit request timeouts.
Suggested fix
Scope the query to the tag's own taxonomy:
ObjectTag.objects.using(using)
.filter(tag__taxonomy_id=instance.taxonomy_id, tag__lineage__startswith=instance.lineage)
The other lineage__startswith queries in openedx_tagging already scope to the taxonomy (api.py, and Tag.descendant_count and Tag.save in models/base.py), so this one is the only exception. A regression test can create two taxonomies with the same root tag value, tag an object in the first, delete the second, and assert that no event is emitted.
- Dominant language
- Python
- Stars
- 10
- Forks
- 35
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 20
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openedx/openedx-core
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
openedx/openedx-core#942 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openedx/openedx-core#922 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
openedx/openedx-core#831 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
openedx/openedx-core#827 ·
Maintainers usually reply within 1 day
-
[FE] Close disabled-control tooltips with EscapePossibly taken @illiphilli claimed this 1 day ago. Open
openedx/openedx-core#941 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in openedx/openedx-core
Similar issues
-
opensubtitlescom: provider rejects pt-PT even though its own converter maps itPossibly taken @paulo-0308 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Diaoul/subliminal#1405 ·
-
Internal ErrorOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
frappe/frappe_docker#2071 ·
Maintainers usually reply within 1 day
-
bug python
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
traceloop/openllmetry#4717 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
The-Pocket/PocketFlow#161 ·
-
comp/desktop P2 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NousResearch/hermes-agent#157702 ·
Maintainers usually reply within 1 day