Skip to content

feat: strip competency tags from duplicated sections and subsections - #39420

Open
bsparks wants to merge 1 commit into
openedx:masterfrom
bsparks:bsparks/808-strip-competency-tags-on-duplicate
Open

bsparks wants to merge 1 commit into
openedx:masterfrom
bsparks:bsparks/808-strip-competency-tags-on-duplicate

Conversation

@bsparks

@bsparks bsparks commented Nov 23, 2026

Copy link
Copy Markdown

Description

Supersedes #39392. The commits are the same as on that pull request.

Implements openedx/openedx-core#808: a duplicate of a section or subsection ends up with no competency tags, and keeps every other tag.

Studio's Duplicate action sends XBLOCK_DUPLICATED once for each duplicated block, and content_tagging.handlers.duplicate_tags copies the source block's tags to the duplicate. A competency tag is meant to be backed by a competency criterion, and a duplicate has none, so a copied competency tag claims a link to the competency that nothing evaluates.

This PR adds a second receiver of XBLOCK_DUPLICATED, strip_competency_tags_from_duplicate_handler in cms/djangoapps/contentstore/signals/handlers.py. For a duplicated chapter or sequential it queues the new task strip_competency_tags_from_duplicate through transaction.on_commit. The task reads the duplicate's tags, finds the competency taxonomies among them with select_competency_taxonomies and is_competency_taxonomy from openedx_learning.api, and for each one calls content_tagging.api.tag_object with the tags to keep. It keeps only a tag that a competency criterion references, and a fresh duplicate has none. content_tagging is unchanged.

Behavior

  • The duplicate of a section or subsection carries no tag from any competency taxonomy once the task has run. Its tags from other taxonomies stay.
  • The original block keeps its tags and its competency criteria. No criteria group or criterion is created, changed, or removed.
  • Duplicating a section queues the task for the section and for each subsection copied with it, because the event is sent for every duplicated block.
  • Units and components queue nothing. They should never have competency tags on them, so a duplicate of one has nothing to remove.
  • A competency tag on the duplicate that a competency criterion references stays. Deleting a tag deletes the criteria on it, so the task leaves a mastery rule that the author added to the duplicate while the task was queued.
  • The task runs in one transaction. A database error in it, or a competency taxonomy that is no longer enabled for the course's organization, is logged with the duplicate's key, and the duplicate keeps all of its tags. A failure to queue the task is logged and does not fail the duplicate request. Running the task again is safe: it removes nothing when no competency tag is left.
  • The task consults no permission, so the author needs no permission beyond the one to duplicate.

Testing

  • pytest cms/djangoapps/contentstore/signals/tests/test_handlers.py -k StripCompetency: the receiver queues the task on commit for a section or subsection, queues nothing for a unit or component, does not fail the commit when the task cannot be queued, and runs after the tag copy when no transaction is open.
  • pytest cms/djangoapps/contentstore/tests/test_tasks.py -k StripCompetency: the task removes the tags of every competency taxonomy, keeps regular tags, keeps a competency tag that a criterion references, and on an error in the second removal logs it and keeps every tag.
  • pytest cms/djangoapps/contentstore/views/tests/test_block.py -k duplicate: duplicating real blocks, including a subsection that has a competency criterion and a request made by a course author without admin rights.

Manual testing

  1. In the course outline in Studio, open the tags drawer of a subsection and add a tag from a regular taxonomy and a tag from a competency taxonomy. Tag its section the same way.
  2. On the Competency Management page, add a mastery rule for that competency on the tagged subsection.
  3. In the course outline, duplicate the subsection. Open the tags drawer on the duplicate: it shows the regular tag and no competency tag.
  4. Duplicate the section. The duplicated section and each subsection in it show their regular tags and no competency tag.
  5. Check the originals: each still shows both tags, and the Competency Management page shows the same rule as before, with nothing added for the duplicates.

Related to openedx/openedx-core#808

🤖 Generated with Claude Code

Duplicating a section or subsection in Studio copies every tag to the
duplicate, including tags from competency taxonomies. The duplicate has
no competency criteria, so the copied competency tag claims a link to
the competency that nothing evaluates.

A new XBLOCK_DUPLICATED receiver in contentstore queues the task
strip_competency_tags_from_duplicate for a duplicated chapter or
sequential, once the current transaction commits. The task removes the
duplicate's tags from competency taxonomies and leaves its other tags.
The tag copy in content_tagging is unchanged.

Receivers run in the order they connect, and the removal has to run
after the copy when no transaction is open, as in Studio's duplicate
request. The handlers module imports the tag copy receiver, and that
import connects it before the new receiver.

The task keeps a competency tag that a competency criterion references,
because deleting the tag would delete a mastery rule the author added
to the duplicate while the task was queued.

The task runs in one transaction. A database error, or a taxonomy no
longer enabled for the organization, is logged with the duplicate's key
and leaves the duplicate's tags as they are. A failure to queue the
task is logged and does not fail the duplicate request.

Related to openedx/openedx-core#808

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 23, 2026
@openedx-webhooks

openedx-webhooks commented Nov 23, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @bsparks!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

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
🔘 Submit a signed contributor agreement (CLA)

⚠️ We ask all contributors to the Open edX project to submit a signed contributor agreement or indicate their institutional affiliation.
Please see the CONTRIBUTING file for more information.

If you've signed an agreement in the past, you may need to re-sign.
See The New Home of the Open edX Codebase for details.

Once you've signed the CLA, please allow 1 business day for it to be processed.
After this time, you can re-run the CLA check by adding a comment below that you have signed it.
If the CLA check continues to fail, you can tag the @openedx/cla-problems team in a comment for further assistance.

🔘 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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Nov 23, 2026
@bsparks
bsparks marked this pull request as ready for review November 23, 2026 17:53

This branch has not been deployed

No deployments
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: Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants