Repository navigation
feat: reject new criteria under archived competency groups (#717) - #899
Conversation
|
Thanks for the pull request, @ufedaseyeuconsultant! This repository is currently maintained by 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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
|
Hi @ufedaseyeuconsultant! Just flagging that some branch conflicts have popped up. Would you mind taking a look? Thanks! |
9e5f022 to
cd9c511
Compare
|
Hi @ufedaseyeuconsultant , this is the AI-generated Code Review (raw - I haven't edited / triaged it yet). |
cd9c511 to
ea5785b
Compare
There was a problem hiding this comment.
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!
|
@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. |
ea5785b to
e1cf491
Compare
|
@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) |
|
@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 |
|
approved it and moved it to @mgwozdz-unicon since you added a comment there. |
2e09d1c to
0cd3436
Compare
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
ormsbee
left a comment
There was a problem hiding this comment.
A few small things inline, and then I think this is ready:
- 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). - Please include the archived group's id in the course-level rejection message.
- 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.| 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. |
There was a problem hiding this comment.
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?
| 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. |
| 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." | ||
| )}) |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
#915 renamed this function, and the merge doesn't conflict here, so it's easy to miss.
| # 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. |
There was a problem hiding this comment.
Likewise.
| ``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 |
There was a problem hiding this comment.
An archived criterion counts again as of 2e09d1c, so this can go back to what's on main.
| 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 |
| 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 |
There was a problem hiding this comment.
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:
- 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. - 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.
0cd3436 to
2081a13
Compare
…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]>
2081a13 to
42a3ae5
Compare
|
@ormsbee Done |
There was a problem hiding this comment.
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.
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]>
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]>
Description
Closes #717.
POST /api/cbe/v1/competencies/<tag_id>/criteria/creates aCompetencyCriterionfor a piece of course content. It either uses a leaf group the client supplies asgroup_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 thearchivedflag onCompetencyCriteriaGroupandCompetencyCriterion. ADR 0002 says archived groups and criteria are hidden from authoring and new associations. With this PR, creating a criterion behaves as follows:group_idthat names an archived leaf is rejected with a 400 keyedgroup_id: "group_id references an archived CompetencyCriteriaGroup, which no longer accepts new associations."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 constraintoel_cbe_criteria_group_one_course_group_per_tag_courseallows only one per competency and course.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.group_idis 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 callsresolve_or_create_leaf_group()) reactivates an archived root right after itsget_or_create(), and rejects an archived course-level group right after itsget_or_create(). The leaf is always newly created there, so it needs no check. The reactivation usessave(), sosimple_historyrecords it.resolve_supplied_leaf_group()adds the archived checks after its existing leaf, tag, and course checks, so a structurally wronggroup_idkeeps 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, mirroringget_courses_with_relative_criteria()._reject_duplicate_criterion()counts every criterion on the content'sObjectTag, archived or not, and picks the 400 message by whether an active one is among the blockers.transaction.atomic()block inassociate_competency_criterion(), under the existing row lock on the competencyTag.No signature, migration, serializer, view, or import-layer change.
associate_competency_criterion()andresolve_supplied_leaf_group()are marked UNSTABLE, so the new rejections need no deprecation.Three details differ from the ticket's Technical Details:
ValidationError, asassociate_competency_criterion()'s other rejections do (the module also raisesCompetencyCriterionArchivedErrorandPermissionDeniedelsewhere), not DRF's. The ticket expected a 500 from Django's exception, butCompetencyCriterionCreateViewdoes not use the tagging exception handler the ticket cites. It translates Django'sValidationErrorinto a DRF 400 itself (rest_api/v1/views.py), so the client gets the same 400 with the field key, andapi.pystays free of HTTP-layer types._reject_if_archived()helper, because they use different keys and messages and there are only two callers.object_id, because the request has nogroup_idand the content's usage key is what selects the archived course-level group.Who is affected
associate_competency_criterion(): the same behaviors, raised as DjangoValidationError.Supporting information
archivedfields this PR checks (merged).docs/openedx_learning/decisions/0002-competency-criteria-model.rst, Decisions 2 and 7: archived groups and criteria are hidden from authoring and new associations.claude-opus-5-5) planned the change and reviewed it; Claude Sonnet 5.5 sub-agents wrote the code and tests under that plan. I reviewed the result.Testing instructions
Automated:
pytest tests/openedx_learning/applets/cbe -o addopts=""(594 tests at this branch's head;-o addopts=""skips the coverage flagstox.iniadds).lint-imports,pylint,pycodestyle,isort --check-only,pydocstyleandmypy --show-traceback(mypy also checks the tests).New tests (16 across
test_api.pyandtest_views.py), one per ticket scenario plus regression guards:group_iderror (unit and view). An active leaf next to an archived one in the same course-level group still resolves.object_iderror 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.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.{"object_id": "<usage key in X>"}to/api/cbe/v1/competencies/<tag_id>/criteria/. Expect 201.archived=Truewithsave()on that criterion's leaf. POST again with{"object_id": "<another usage key in X>", "group_id": <that leaf id>}. Expect 400 with thegroup_idarchived message.{"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 theobject_idarchived message, and the root still archived.{"object_id": "<usage key in Y>"}. Expect 201, the root reactivated, and X's course-level group still archived.Other information
StudentCompetencyCriteriaGroupStatusrows on a reactivated root: the roll-up onmainreads and writes these rows with noarchivedfilter, 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._create_leaf_group()cites it.Taglock this flow holds, so a concurrent create and archive serialize.🤖 Generated with Claude Code
Summary by CodeRabbit