Skip to content

feat: reject new criteria under archived competency groups (#717) - #899

Merged
ormsbee merged 1 commit into
openedx:mainfrom
ufedaseyeuconsultant:ufedaseyeu/717--enforce-archived-in-cc-creacion
Nov 17, 2026
Merged

ormsbee merged 1 commit into
openedx:mainfrom
ufedaseyeuconsultant:ufedaseyeu/717--enforce-archived-in-cc-creacion

Conversation

@ufedaseyeuconsultant

@ufedaseyeuconsultant ufedaseyeuconsultant commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes #717.

POST /api/cbe/v1/competencies/<tag_id>/criteria/ creates a CompetencyCriterion for a piece of course content. It either uses a leaf group the client supplies as group_id (the supplied path), or derives the root, course-level, and leaf groups for the competency and the content's course (the derive path). Until now that flow ignored the archived flag on CompetencyCriteriaGroup and CompetencyCriterion. ADR 0002 says archived groups and criteria are hidden from authoring and new associations. With this PR, creating a criterion behaves as follows:

  • A supplied group_id that names an archived leaf is rejected with a 400 keyed group_id: "group_id references an archived CompetencyCriteriaGroup, which no longer accepts new associations."
  • On the derive path, an archived course-level group for the content's course is rejected with a 400 keyed object_id: "The course-level CompetencyCriteriaGroup for this competency and course is archived and no longer accepts new associations: group ." No replacement course-level group is created, because the unique constraint oel_cbe_criteria_group_one_course_group_per_tag_course allows only one per competency and course.
  • On the derive path, an archived root group is reactivated (archived=False) and reused. A root is archived once every course-level group under it is archived, so without this, archiving a competency's last course would block new criteria for every course. The root's archived children stay archived. If a later check in the same request rejects it, the transaction rolls the reactivation back.
  • An archived criterion keeps blocking a new criterion for the same content: in its group when group_id is supplied, and anywhere under the competency on the derive path. When every blocking criterion is archived, the 400 says the content was previously associated and the association archived, so the author is not left staring at a duplicate error for content they cannot see. A different active group still accepts the content, as a deliberate second association. Decided by the ticket owner in [BE] Enforce archived in Competency Criteria creation #717 (comment): archiving is permanent below the root for MVP, and one criterion row per content per group keeps the data clean for a post-MVP unarchive.

How it works

All changes are in src/openedx_learning/applets/cbe/api.py:

  • _create_leaf_group() (the derive path, which the ticket calls resolve_or_create_leaf_group()) reactivates an archived root right after its get_or_create(), and rejects an archived course-level group right after its get_or_create(). The leaf is always newly created there, so it needs no check. The reactivation uses save(), so simple_history records it.
  • resolve_supplied_leaf_group() adds the archived checks after its existing leaf, tag, and course checks, so a structurally wrong group_id keeps its existing error. It rejects an archived leaf and also a leaf whose course-level parent is archived: the parent is already loaded, so the check costs no query, and it defends against rows written outside the API, mirroring get_courses_with_relative_criteria().
  • _reject_duplicate_criterion() counts every criterion on the content's ObjectTag, archived or not, and picks the 400 message by whether an active one is among the blockers.
  • All three run inside the existing transaction.atomic() block in associate_competency_criterion(), under the existing row lock on the competency Tag.

No signature, migration, serializer, view, or import-layer change. associate_competency_criterion() and resolve_supplied_leaf_group() are marked UNSTABLE, so the new rejections need no deprecation.

Three details differ from the ticket's Technical Details:

  • The rejections raise Django's ValidationError, as associate_competency_criterion()'s other rejections do (the module also raises CompetencyCriterionArchivedError and PermissionDenied elsewhere), not DRF's. The ticket expected a 500 from Django's exception, but CompetencyCriterionCreateView does not use the tagging exception handler the ticket cites. It translates Django's ValidationError into a DRF 400 itself (rest_api/v1/views.py), so the client gets the same 400 with the field key, and api.py stays free of HTTP-layer types.
  • The two checks are inline instead of a shared _reject_if_archived() helper, because they use different keys and messages and there are only two callers.
  • The derive-path rejection is keyed object_id, because the request has no group_id and the content's usage key is what selects the archived course-level group.
  • An archived group is a 400 here while the group PATCH endpoint returns a 409 for the same state. The difference is deliberate: this ticket's scenarios specify a 400 validation error on create, and the 409 is the update endpoint's conflict convention from [BE] Update/Edit Competency Criteria Group #760.

Who is affected

  • Course Authors creating competency criteria: a request that targets an archived leaf, or the archived course-level branch of a course, now gets a 400 instead of silently adding to archived rules. Re-adding content whose earlier criterion was archived is rejected with a 400 naming the archived association; the content can still be added to a different active group.
  • Developers calling associate_competency_criterion(): the same behaviors, raised as Django ValidationError.

Supporting information

Testing instructions

Automated:

  1. pytest tests/openedx_learning/applets/cbe -o addopts="" (594 tests at this branch's head; -o addopts="" skips the coverage flags tox.ini adds).
  2. The quality checks as CI runs them: lint-imports, pylint, pycodestyle, isort --check-only, pydocstyle and mypy --show-traceback (mypy also checks the tests).

New tests (16 across test_api.py and test_views.py), one per ticket scenario plus regression guards:

  • Supplied archived leaf: rejected with a group_id error (unit and view). An active leaf next to an archived one in the same course-level group still resolves.
  • Archived root on the derive path: reactivated, still exactly one root, a new course-level group and leaf for the new course under it, and the other course's archived course-level group untouched (unit and view); the reactivation history row is asserted by the unit test.
  • Archived course-level group on the derive path: rejected with an object_id error and nothing created, under an active root (unit and view) and under an archived root, where the root is still archived afterwards because the transaction rolled back.
  • A different course under the same competency still succeeds when another course's course-level group is archived.
  • Re-association: with the earlier criterion archived, re-adding the same content is rejected with the archived-association 400, on the derive path (unit and view) and on the supplied path into the same group (view); the duplicate check fires before any group state is consulted. A different active group still accepts the content (view), and a mix of active and archived blockers keeps the plain duplicate message (unit).
  • An active leaf under an archived course-level group is rejected on the supplied path, and a request rejected by the hierarchy-dominance check after the root was reactivated rolls the reactivation back. With the criterion, its leaf, its course-level group, and the root all archived, re-association is rejected with the archived-association 400, because the duplicate check fires before any group state is consulted.

Each new test was checked by temporarily breaking the code line it covers and confirming it fails for the stated reason.

Manual, against a devstack, with a competency tag <tag_id> and two course runs X and Y. These steps archive groups from a Django shell; the DELETE endpoints (#674 and #675) archive only when learner status exists, and the shell sets the state directly.

  1. POST {"object_id": "<usage key in X>"} to /api/cbe/v1/competencies/<tag_id>/criteria/. Expect 201.
  2. In a shell, set archived=True with save() on that criterion's leaf. POST again with {"object_id": "<another usage key in X>", "group_id": <that leaf id>}. Expect 400 with the group_id archived message.
  3. Archive X's course-level group and the root the same way. POST {"object_id": "<a third usage key in X>"} (fresh content: re-posting step 1's key hits the archived-association duplicate message first). Expect 400 with the object_id archived message, and the root still archived.
  4. POST {"object_id": "<usage key in Y>"}. Expect 201, the root reactivated, and X's course-level group still archived.

Other information

  • The one-course closure stands: when the last live criterion in a course is archived, the cascade archives the course-level group, and new content from that course gets the course-level 400. The ticket owner confirmed this in [BE] Enforce archived in Competency Criteria creation #717 (comment), matching the decision on [BE] Delete Competency Criterion #674 (comment), and is updating the ticket's user story and scenarios to say so.
  • Supplied path: an active leaf that holds an archived criterion for the same content refuses a second criterion for it with the archived-association 400, per the ticket owner's ruling in [BE] Enforce archived in Competency Criteria creation #717 (comment). A different active group still accepts the content; the tests pin the 400 for the same group and the derive path, and the 201 for a different group.
  • The ticket's open question about StudentCompetencyCriteriaGroupStatus rows on a reactivated root: the roll-up on main reads and writes these rows with no archived filter, so a reactivated root's old roll-up rows carry over and are read like any other root's. ADR 0004 only ever raises statuses automatically, and the competency-level status is keyed by user and tag, so the reactivation itself changes nothing for recorded learners. Whether old rows should be recomputed against rebuilt rules belongs to the roll-up work.
  • ADR 0002 already records root reactivation as the one reversible exception to permanent archiving: the amendment landed with [BE] Enforce one root Competency Criteria Group per competency in the database #872 (Decisions 2 and 7 and Rejected Alternative 7), and the reactivation comment in _create_leaf_group() cites it.
  • The delete paths of [BE] Delete Competency Criterion #674 and [BE] Build endpoint for removing a Competency Criteria Group #675 (both merged) take the same competency Tag lock this flow holds, so a concurrent create and archive serialize.
  • No migrations.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Creating a competency leaf can now reuse an archived root group, while archived course-level groups and archived leaves are rejected with clear validation errors.
    • Archived criteria now count as duplicates during association, preventing a criterion from being associated again when a matching archived criterion already exists.
    • Failed association attempts leave archived groups unchanged and avoid creating unintended groups or criteria.
    • Existing active groups and criteria remain available for valid associations.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 22, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @ufedaseyeuconsultant!

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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Oct 22, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Oct 27, 2026
@mphilbrick211

Copy link
Copy Markdown

Hi @ufedaseyeuconsultant! Just flagging that some branch conflicts have popped up. Would you mind taking a look? Thanks!

@ufedaseyeuconsultant
ufedaseyeuconsultant force-pushed the ufedaseyeu/717--enforce-archived-in-cc-creacion branch from 9e5f022 to cd9c511 Compare October 27, 2026 22:37
@mphilbrick211 mphilbrick211 moved this from Ready for Review to Waiting on Author in Contributions Nov 4, 2026
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to Ready for Review in Contributions Nov 4, 2026
@jesperhodge

Copy link
Copy Markdown
Contributor

review-pr-899.md

Hi @ufedaseyeuconsultant , this is the AI-generated Code Review (raw - I haven't edited / triaged it yet).
I don't see any meaningful finding under must-haves, so there is no action needed on your side right now. I will proceed with a human code review.

@ufedaseyeuconsultant
ufedaseyeuconsultant force-pushed the ufedaseyeu/717--enforce-archived-in-cc-creacion branch from cd9c511 to ea5785b Compare November 4, 2026 19:51

@jesperhodge jesperhodge left a comment •

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.

Hi @ufedaseyeuconsultant , thanks for the PR. Looks good!

I've reviewed the PR. Everything tested well.

The AI code review found some things that look worth addressing. Can you go through review-pr-899.md and address its findings?

Also the AI code review did flag a point that I think is worth a look:

"Ticket #717's user story and scenario 7 promise that an old archived association never blocks a new one, but the ticket's description, its out-of-scope list, and ADR 0002 keep a course with an archived course-level group closed, and the code follows the closed-course side."

The ticket itself contradicts itself here, so this is probably best settled in the ticket discussion, and the answer may affect the PR.

One more thing: the PR description says you left a comment on #717 about this, but I couldn't find one. Could you double-check the description and make sure everything is correct? Sometimes AI tools can slip details like this in.

Another thing in the PR description is the point:
"Supplied path: an active leaf that holds an archived criterion for the same content now accepts a second criterion for it, because the duplicate check ignores archived criteria. The ticket describes re-association only on the derive path. I've asked on #717 whether this is intended. No test pins it yet."
I think there's no question for that in 717 either, could you check that as well?

Thank you!

@ufedaseyeuconsultant

Copy link
Copy Markdown
Contributor Author

@jesperhodge Addressed everything from the review file: rebased onto current main (the conflict was the one docstring; it now also says what the reactivation relies on for serialization), the stale duplicate-check comment is fixed, the supplied path now also rejects a leaf under an archived course-level group, the get_or_create rationale is back with the ADR 0002 / #872 citation, and the supplied-path re-association got its view test plus a rollback test through main's dominance check. The two ticket questions you couldn't find are now actually posted on #717 - sorry about that, the description claimed them before they existed. The description is rewritten: stale counts and claims fixed, the planned ADR amendment dropped (it already landed via #872), and the 400-on-create vs 409-on-update difference recorded as deliberate. On the contradiction: Mary already accepted the closed-course consequence for MVP on #674, so I proposed on #717 to narrow the two user-story bullets and scenario 7 accordingly.

@ufedaseyeuconsultant
ufedaseyeuconsultant force-pushed the ufedaseyeu/717--enforce-archived-in-cc-creacion branch from ea5785b to e1cf491 Compare November 10, 2026 12:27
@mgwozdz-unicon

Copy link
Copy Markdown
Contributor

@ufedaseyeuconsultant Please see my comment response on the ticket since I am requesting that an archived criterion blocks the creation of a new criterion for the same content in the same group instead of allowing it. #717 (comment)

@ufedaseyeuconsultant

Copy link
Copy Markdown
Contributor Author

@mgwozdz-unicon @jesperhodge Implemented Mary's decision from the ticket: the archived=False filter is gone from the duplicate check, so an archived criterion blocks a new criterion for the same content again - in its group when group_id is supplied, and anywhere under the competency on the derive path. When every blocker is archived, the 400 now says the association was archived instead of the plain duplicate message, so an author who can't see the content doesn't read it as a bug. Tests flipped accordingly: same-group re-add is a 400, the derive-path re-add is a 400, a different active group still gets a 201, and a mixed active-plus-archived case keeps the plain duplicate message. This supersedes the re-association part of my previous comment - the view test that pinned the 201 there now pins the 400. The PR description is updated to match, and the suite is green

@jesperhodge

Copy link
Copy Markdown
Contributor

approved it and moved it to @mgwozdz-unicon since you added a comment there.

@ufedaseyeuconsultant
ufedaseyeuconsultant force-pushed the ufedaseyeu/717--enforce-archived-in-cc-creacion branch from 2e09d1c to 0cd3436 Compare November 17, 2026 17:31
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The API now rejects archived supplied groups and archived course-level groups, reactivates archived roots during derived creation, and checks archived criteria when preventing duplicate associations. Unit and endpoint tests cover these cases, including rollback behavior.

Changes: Archived criterion handling

Layer / File(s) Summary
Archived group handling
src/openedx_learning/applets/cbe/api.py, tests/openedx_learning/applets/cbe/test_api.py, tests/openedx_learning/applets/cbe/test_views.py
Derived creation reactivates an archived root but rejects an archived course-level group. Supplied archived leaves and archived course-level parents are rejected. Tests cover group reuse, validation errors, and rollback after rejection.
Archived criterion duplicate checks
src/openedx_learning/applets/cbe/api.py, tests/openedx_learning/applets/cbe/test_api.py, tests/openedx_learning/applets/cbe/test_views.py
Duplicate checks include archived criteria. The check spans all groups when no group is supplied and only the specified group otherwise. Tests cover archived and active matches, different-group associations, and rollback behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Possibly related issues

Possibly related PRs

  • openedx/openedx-core#879 — It archives criteria in place, and this PR makes archived criteria block duplicate associations.
  • openedx/openedx-core#915 — It shares the blocked-course check with criterion creation, where this PR changes archived-criterion duplicate handling.

Suggested reviewers: alezconsultant, mgwozdz-unicon

Merge Risk: Minimal · up to 42a3a

This change rejects new criteria under archived competency groups and makes archived criteria block duplicate associations. No concrete merge-blocking risk was identified, and the change is covered by tests.

Security architecture risk: Minimal · up to 42a3a

The change tightens archived-state checks while retaining existing authorization and transaction protections. Reactivating a shared root leaves archived course branches archived. No introduced or worsened material security or failure-containment risk was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new shared-state effect is reactivation of the root for the selected competency, which can span courses. It does not unarchive existing course branches or criteria: the mutation changes only the root, and the authoring tree still excludes archived groups, unreachable descendants and archived criteria.

Trust Boundaries and Controls

  • observed — Client-controlled tag, content and group identifiers still pass through endpoint authentication and the object-scoped can_tag_object permission check before association. A supplied group must belong to the selected competency and the content's course before the new archived-state checks run. These authorization and identity checks predate this PR.

Resilience and Maintainability Implications

  • inferred — The inspected create and archive entrypoints serialize on the same competency Tag row. Under the documented READ COMMITTED assumption, concurrent creates cannot bypass the duplicate check, and concurrent criterion or subtree archiving cannot interleave with the new archived-state checks and reactivation.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat: reject new criteria under archived competency groups (#717)" matches the main change. The changeset rejects criterion creation under archived supplied leaves and archived course-level…
Linked Issues check Passed Issue #717 is the only directly linked, active issue, so its coding requirements apply. The reviewed head implements them in src/openedx_learning/applets/cbe/api.py:

1. Archived supplied leaf: resolv…
Out of Scope Changes check Passed The changes in src/openedx_learning/applets/cbe/api.py map to objectives of #717: the archived leaf and archived-parent checks, the archived course-level rejection, root reactivation, archived-aware d…
Full details: Title check

Explanation

The title "feat: reject new criteria under archived competency groups (#717)" matches the main change. The changeset rejects criterion creation under archived supplied leaves and archived course-level groups, reactivates archived roots on the derive path, and makes archived criteria block duplicate associations. The title names the central behavior and omits some detail such as the root reactivation and duplicate-error handling, which is expected for a short title. The PR number in the title (#717) refers to the linked issue, not the PR itself, but this does not make the title misleading.

Full details: Linked Issues check

Explanation

Issue #717 is the only directly linked, active issue, so its coding requirements apply. The reviewed head implements them in src/openedx_learning/applets/cbe/api.py:

  1. Archived supplied leaf: resolve_supplied_leaf_group() raises ValidationError keyed "group_id" for an archived leaf. It also rejects a leaf whose course-level parent is archived.
  2. Archived course-level group on the derive path: _create_leaf_group() raises ValidationError keyed "object_id" and creates no replacement group. The unique constraint is cited as the reason.
  3. Archived root reactivation: _create_leaf_group() sets root.archived = False and calls save(), so simple_history records it. Archived children are not changed.
  4. Rollback: the docstrings state that the reactivation and the checks run inside the tag-lock transaction. The atomic block in associate_competency_criterion() was beyond the readable output of my inspection, so I did not see it directly. The PR summary also describes a test that checks the rollback.
  5. Duplicate checks: _reject_duplicate_criterion() counts archived criteria. When all blockers are archived, it raises the archived-association message. A different active group is still allowed.
  6. Signatures are unchanged. The diff shows no migration, serializer, view, or endpoint change.

The PR adds 16 tests across test_api.py and test_views.py, according to the summary. I did not run them. The non-test coding requirements are met by the visible code.

Full details: Out of Scope Changes check

Explanation

The changes in src/openedx_learning/applets/cbe/api.py map to objectives of #717: the archived leaf and archived-parent checks, the archived course-level rejection, root reactivation, archived-aware duplicate checks, and their docstrings. The change set has no migration, view, serializer, or endpoint change. The test changes in test_api.py and test_views.py support the same objectives. The ADR 0002 amendment (#872) and the other cited issues are context and are not part of this diff. I found no unrelated change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b1f967fa-af67-4fde-ada6-83b06549c987
Commits

Reviewing files that changed from the base of the PR and between 2081a13 and 42a3ae5.

Files selected for processing: 2

  • src/openedx_learning/applets/cbe/api.py
  • tests/openedx_learning/applets/cbe/test_views.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@ormsbee ormsbee left a comment

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.

A few small things inline, and then I think this is ready:

  1. Please rebase onto main. The only conflict is the _create_leaf_group() docstring, but two comments also need updating for what merged in the meantime (#879's lock and #915's rename).
  2. Please include the archived group's id in the course-level rejection message.
  3. Please have the scenario 7 view test get to its archived state through the real delete path, now that it's on main.

There's also a one-line docstring suggestion in test_views.py.

On the ticket's open question for the reviewer, about StudentCompetencyCriteriaGroupStatus rows on a reactivated root: I agree with your answer in the description. The next rollup recomputes the root from its children, but raise_status() never lowers a stored row, so a status that a learner already holds carries over to the rebuilt rules. That's consistent with learners keeping every status they've earned, and which children the rollup should read is #929's question, not this PR's.

The PR description still has three sentences from before the duplicate-check decision and before #879 merged: the testing section says the fully archived branch gets the course-level error (the code and the test give the archived-association message), the supplied-path bullet under "Other information" still opens by saying an archived criterion no longer blocks, and the lock bullet says "once those PRs land" about #674. Please update those, then squash, and I'll merge. Thank you!


Claude usage Claude drafted this review and ran the following for me on 2e09d1c: a trial merge with current `main` (98bf3f7; one conflict, in the `_create_leaf_group()` docstring), the CBE suite on SQLite on that merge (674 passed, 10 skipped), and the two throwaway tests described inline, which archive through `delete_or_archive_competency_criterion()` and then run this PR's create paths. The throwaway tests aren't in the branch.

Comment thread src/openedx_learning/applets/cbe/api.py Outdated
Comment on lines +299 to +301
Must run inside a transaction holding the tag row lock. That lock serializes the reactivation
and the two archived checks against other creates, but not against the archive cascade until
the endpoints for #674 and #675, which take the same lock, land.

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.

This docstring is where the conflict with main is. When you resolve it, the last clause needs to change too: #879 has merged and its delete path takes the same Tag lock, so the reactivation and the archived checks are already serialized against that archive cascade. Maybe something like this?

Suggested change
Must run inside a transaction holding the tag row lock. That lock serializes the reactivation
and the two archived checks against other creates, but not against the archive cascade until
the endpoints for #674 and #675, which take the same lock, land.
Must run inside a transaction holding the tag row lock. That lock serializes the reactivation
and the two archived checks against other creates and against the archive cascade in
``delete_or_archive_competency_criterion()``, which takes the same lock.

Comment thread src/openedx_learning/applets/cbe/api.py Outdated
Comment on lines +323 to +327
if course_level_group.archived:
raise ValidationError({"object_id": _(
"The course-level CompetencyCriteriaGroup for this competency and course is archived "
"and no longer accepts new associations."
)})

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.

Please include the course-level group's id in this message, the way the bulk update's refusal already does and as the ticket asked for, so that whoever gets the "why can't I add content from this course?" report can go straight to the row. The caller never named this group, and get_competency_criteria_tree() leaves archived groups out.

Comment thread src/openedx_learning/applets/cbe/api.py Outdated
raise ValidationError({"group_id": _(
"group_id references an archived CompetencyCriteriaGroup, which no longer accepts new associations."
)})
# Mirrors the defense get_courses_with_relative_criteria() applies to rows written outside the API.

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.

#915 renamed this function, and the merge doesn't conflict here, so it's easy to miss.

Suggested change
# Mirrors the defense get_courses_with_relative_criteria() applies to rows written outside the API.
# Mirrors the defense get_courses_with_live_criteria() applies to rows written outside the API.

An active leaf under an archived course-level group is rejected, keyed ``group_id``.

Only rows written outside the API produce this state. The check mirrors
``get_courses_with_relative_criteria()``, which also treats such a leaf as archived.

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.

Likewise.

Suggested change
``get_courses_with_relative_criteria()``, which also treats such a leaf as archived.
``get_courses_with_live_criteria()``, which also treats such a leaf as archived.


Rejected regardless of which group the existing criterion is actually in: with no group_id
supplied, there's no way to know which group slot this request intends, so any existing
supplied, there's no way to know which group slot this request intends, so any active

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.

An archived criterion counts again as of 2e09d1c, so this can go back to what's on main.

Suggested change
supplied, there's no way to know which group slot this request intends, so any active
supplied, there's no way to know which group slot this request intends, so any existing

Comment on lines +656 to +658
Scenario 6 of #717 at the POST level: an archived criterion blocks re-association into its own leaf.

The leaf is active and holds only an archived criterion for the content. A request supplying that

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.

Now that #879 is on main, please build this state by deleting the criterion through the API (or the DELETE endpoint) instead of setting archived by hand, with a second criterion keeping the leaf active as the ticket's scenario has it. (It's scenario 7 in the ticket as it reads now.)

As written, the leaf is active while holding only an archived criterion, which the cascade never leaves behind: it archives a group whose remaining children are all archived. More generally, this PR and #879 were each tested against a hand-built copy of the other's output, and none of the new tests runs a real delete followed by a create.

Claude ran that as two throwaway tests on a trial merge with main, and both passed:

  1. Course X's only criterion, with a learner status, removed through delete_or_archive_competency_criterion(): everything up to the root was archived. New content from X then got the course-level error with the root still archived, content from course Y reactivated the root, and hard-deleting Y's criterion archived the root again.
  2. Scenarios 7 and 8 as the ticket has them, with the criterion archived through the real delete: the same leaf refused the content with the archived message, and a different leaf accepted it.

So I don't expect the new setup to turn anything up. I'd just like the two halves pinned together.

@ufedaseyeuconsultant
ufedaseyeuconsultant force-pushed the ufedaseyeu/717--enforce-archived-in-cc-creacion branch from 0cd3436 to 2081a13 Compare November 17, 2026 20:59
…enedx#717)

Creating a criterion now respects the archived flag on groups and
criteria, per ADR 0002: archived rows are hidden from new associations.

- A supplied group_id naming an archived leaf, or a leaf whose
  course-level parent is archived, is rejected with a 400 keyed
  group_id.
- On the derive path, an archived course-level group is rejected with
  a 400 keyed object_id that names the group's id, since the caller
  never named the group and the tree read leaves archived groups out.
- On the derive path, an archived root is reactivated and reused: a
  root is archived once its last course-level group is, so rejecting
  it would block new criteria for every course of the competency. The
  root's archived children stay archived, and a later rejection in the
  same request rolls the reactivation back.
- An archived criterion keeps blocking re-association of the same
  content, in its group when group_id is supplied and anywhere under
  the competency on the derive path. When every blocker is archived,
  the 400 says the earlier association was archived. A different
  active group still accepts the content.

The checks run inside the existing transaction under the competency's
Tag row lock, which serializes them against other creates and against
the archive cascade of the delete endpoints, which take the same lock.

Co-authored-by: David Ormsbee <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
@ufedaseyeuconsultant
ufedaseyeuconsultant force-pushed the ufedaseyeu/717--enforce-archived-in-cc-creacion branch from 2081a13 to 42a3ae5 Compare November 17, 2026 21:02
@ufedaseyeuconsultant

Copy link
Copy Markdown
Contributor Author

@ormsbee Done

@ormsbee ormsbee left a comment •

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.

Thank you for the quick turnaround. This looks good to me.


Claude usage

Claude drafted this review and ran the following for me on 42a3ae5: a comparison of this PR's diff against main before and after the rebase and squash (the only differences are the changes from the last round), the CBE suite on SQLite (732 passed, 10 skipped), and a throwaway test of the group delete from #936, which merged after the last round. It archived a course-level group in one case and a leaf group in the other through delete_or_archive_competency_criteria_group(), each with a learner status, and then ran this PR's create paths: the course-level error named the group, the archived content got the archived-association message, the archived leaf was refused, and content from another course reactivated the root. It passed, and it isn't in the branch.

@ormsbee
ormsbee merged commit 8b02e7c into openedx:main Nov 17, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Contributions Nov 17, 2026
mgwozdz-unicon pushed a commit to openedx/openedx-platform that referenced this pull request Nov 18, 2026
Regenerated via `make upgrade-package package=openedx-core`. Picks up
openedx/openedx-core#856 (archived and deletion_locked flags on the
tagging models), released in 1.24.0; openedx/openedx-core#936 (the
delete-or-archive endpoint for a CompetencyCriteriaGroup,
openedx/openedx-core#675), released in 1.25.0; and
openedx/openedx-core#899 (archived state enforced when creating a
competency criterion, openedx/openedx-core#717), released in 1.26.0,
so the Competency-Based Education (CBE) removal flows can go to QA.

Related to openedx/openedx-core#675 and openedx/openedx-core#717

Co-authored-by: Claude Fable 5 <[email protected]>
mgwozdz-unicon pushed a commit to openedx/frontend-app-authoring that referenced this pull request Nov 20, 2026
Each Course Group and each Rule Group in the Competency Criteria
Associations panel on the Competency Management page gets a ⋮ menu on
courses the author can edit. The menu's item is "Remove group" on a
Rule Group and "Remove from {competency}" on a Course Group. Choosing
it deletes the group right away. The confirmation dialog is tracked in
openedx/openedx-core#786.

The delete sends DELETE to the criteria group URL and then refetches
the competency's groups for the listed courses. A 404 means another
author already deleted the group and counts as success. Any other
failure shows an error toast. Discarding an unsaved Rule Group happens
on the client without a request. While a delete is in flight, every ⋮
toggle, every "+ Rule" and "+ Rule Group" control, and every subsection
select control is disabled, and a second delete is dropped.

When the refetch lands, the reducer picks the next selection from the
page order recorded before the request: the nearest Rule Group above or
below in the same Course Group, then the neighboring Course Group, then
a Course Group another author added in the meantime, and otherwise the
empty state. The provider also issues a one-shot keyboard focus
request, because the ⋮ button that had keyboard focus leaves the page
with its group. After a failed delete, keyboard focus returns to that
group's ⋮ toggle.

CompetencyAssociationsPanel renders one provider outside both layouts
and renders the course pane into the mounted layout through a portal,
so resizing the window across the desktop breakpoint keeps the
selection and the in-flight delete state.

The module's "focus" names for the selected group and rule box are
renamed to "selection", so the remaining "focus" names refer only to
browser keyboard focus. `apiUrls.updateCompetencyCriteriaGroup` is
renamed to `apiUrls.competencyCriteriaGroup`, because the URL serves
both the PATCH and the DELETE.

Requires the DELETE endpoint from
openedx/openedx-core#936 and
openedx/openedx-core#899 (openedx-core 1.26.0).

Implements openedx/openedx-core#709.

Co-authored-by: AShatsila <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[BE] Enforce archived in Competency Criteria creation

6 participants