Repository navigation
Description
Summary
A tag import (CSV or JSON, with the optional previous_id column from #673) must reject a row whose parent_id is its current parent's pre-import id when the same file renames that parent. It must keep accepting a child that names the parent's id after the import (the end-state id), also when two parents swap their ids.
Fixing this showed that several neighboring cases went wrong in the same code: parent references depended on the order of the rows, kept children could be lost to the delete cascade, parent cycles and imports deeper than the depth limit were not rejected at the Plan step, and some valid imports failed partway through. Each of those is described below with its own acceptance criteria, because the fix for this issue delivers them too.
In the error messages below, "Row N" is the N-th data row of the file, counting from 1. In a CSV file that is spreadsheet line N + 1, because the header is line 1. In a JSON file it is the N-th entry of tags. In the import log, an error raised by a row's action starts with that action, for example Action error in 'update_parent' (#6): Row 2: .... The #6 is the action's number in the plan, which can differ from the row number because the plan adds its own steps and builds a parent's row before its children's rows. The row is the Row N part.
Problem A: a stale parent_id of an existing child is accepted
UpdateParentTag.applies_for decides whether a row changes its tag's parent by comparing the row's parent_id with the external_id of the tag's parent before the import. When the two match, the row is "no change", so _validate_parent never runs for it.
Take an existing child tag_2 under tag_1. The file renames tag_1 to tag_50 and keeps the tag_2 row with parent_id: tag_1. The tag_2 row matches the pre-import parent, so it is "no change", and the import accepts it silently. After the import no tag has the id tag_1, so the row's parent_id names nothing. #673's scenario "a child row referencing its parent's pre-import external_id is rejected" requires rejecting exactly this file.
The existing regression tests only used a brand-new child. A new child is created through CreateTag, which runs _validate_parent, so those tests passed while the existing-child case was broken.
Problem B: the first fix rejected valid swaps
A first attempt at fixing Problem A (reverted) rejected every parent_id that named an id which one rename row gives up and another rename row takes, as happens in a swap. That also rejected a child that names the correct end-state id. For example, when tag_1 and tag_3 swap ids, tag_4 (a child of the old tag_3) correctly says parent_id: tag_1, and the first fix rejected it. As a result, two swapped parents with children could not be imported at all.
Root cause and proposed fix
Both problems come from keying the validation on the wrong condition. A row that names its parent's pre-import id is only a problem when the same file gives that id away: the file renames the parent to another id, or, in a full replace import, the file deletes the parent and renames another tag onto its id.
The fix treats such a row as a parent change, so the per-row parent validation runs for it even though its parent_id matches the parent's pre-import id. When the file renames the parent away, the validation rejects the row. The only ambiguous reading is a row whose parent_id equals the pre-import id of its own current parent while another row of the same file takes that id, as in a swap. That row is rejected too. The error names the row and the parent's new id, for example: Row 2: Parent tag tag_1 is renamed to tag_50 in this file; use tag_50 as the parent_id. When another row takes the id, the error adds a second sentence for the other possible meaning: To move under the tag that takes the id tag_1 in this file instead, import the id changes and the move as two separate files. A child that names the end-state id of its parent is accepted. When the file deletes the parent and renames another tag onto its id, a child that names that id moves under the renamed tag.
A comment in the import plan says that _validate_parent reports a reference to an id the import renames away. Before this fix the comment was wrong for a "no change" row, which never called _validate_parent. With the fix the comment holds, because such a row is now a parent change and reaches _validate_parent.
Acceptance criteria
Every criterion in this issue must hold whatever the order of the rows in the file.
- [BE] Support editing an existing tag's external_id (Competency ID) on taxonomy re-import #673's scenario "a child row referencing its parent's pre-import external_id is rejected" is rejected:
- Given a taxonomy where
tag_2is an existing child oftag_1 - When the admin imports a file that renames
tag_1totag_50and keeps thetag_2row withparent_id: tag_1 - Then the Plan step rejects the import with an error that names the
tag_2row and says to usetag_50as theparent_id. With thetag_2row as the second row, the error isRow 2: Parent tag tag_1 is renamed to tag_50 in this file; use tag_50 as the parent_id. - And nothing in the taxonomy changes.
- Given a taxonomy where
- A swap of two parents with children succeeds:
- Given
tag_2undertag_1andtag_4undertag_3 - When the admin imports a full replace file (
replace=True) that renamestag_3totag_1andtag_1totag_3, withtag_2sayingparent_id: tag_3andtag_4sayingparent_id: tag_1 - Then the import succeeds
- And each child stays on the same physical parent:
tag_2is under the tag now calledtag_3, andtag_4is under the tag now calledtag_1.
- Given
- An ambiguous swap reference is still rejected:
- Given
tag_2undertag_1 - When the file swaps the ids of
tag_1andtag_3, and thetag_2row still saysparent_id: tag_1 - Then the Plan step rejects the import, because after the import
tag_1names the oldtag_3, so the row could mean "stay with my parent" or "move under the tag now calledtag_1" - And the error names the
tag_2row, says to usetag_3as theparent_id, and says how to make the other move. With thetag_2row as the third row, the error isRow 3: Parent tag tag_1 is renamed to tag_3 in this file; use tag_3 as the parent_id. To move under the tag that takes the id tag_1 in this file instead, import the id changes and the move as two separate files.
- Given
test_generate_actions_parent_id_new_id_after_earlier_rename_acceptedand thetest_generate_actions_rename_external_id_replace_skips_delete*tests continue to pass unchanged.
References
- [BE] Support editing an existing tag's external_id (Competency ID) on taxonomy re-import #673, the ticket that introduced
previous_id, and its acceptance scenarios. - ADR 0010:
docs/openedx_tagging/decisions/0010-mutable-tag-external-id.rst. - Review comments on feat: support editing an existing tag's external_id on taxonomy re-im… #804 that led to this issue:
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
test: keep one test per openedx#858 scenario in the import acceptance…
fix: reject stale parent_id in tag import and make parent changes ord…
dvarenikqaconsultant commentedon Oct 29, 2026
Test report: Tag import parent_id re-validation (#858)
Environment: Master Sandbox, https://studio.master.openedx.io (openedx-core 1.17.0, which includes the fix from #877)
Test user:
dmitryvarenikqa(staff)Test type: API (Postman, Studio REST API:
PUT .../tags/import/plan/andPUT .../tags/import/) and UI (Studio taxonomy import wizard)Result: All test cases passed. No defects found.
Stale parent_id after a parent rename (AC 1)
tag_1is renamed totag_50, and childtag_2still hasparent_id=tag_1parent_idwritten in a different letter case (TAG_1)Child references the parent's new id (AC 4)
tag_1is renamed totag_50, and the child usesparent_id=tag_50tag_50"Tag 1" with childtag_2parent_id=TAG_50in a different letter casetag_2is undertag_50tag_1takes the id of an existing roottag_3that is not in the filetag_3is deleted, andtag_1is renamed in placetag_3and renamestag_1totag_3; the export shows one tag,tag_3"Tag 1"; the numeric tag id stays the same (13719)Swapping the ids of two parents (AC 2 and AC 3)
tag_1andtag_3swap ids, parent rows first, and each child points to its parent's new idtag_3"Tag 1" >tag_2,tag_1"Tag 3" >tag_4. No "Move ... to the root first" step, because the children keep their physical parentstag_2still points to the old idtag_1tag_4points to the old idtag_2row has no errortag_1tag_2to the root first, then to the new parent, which is named explicitlytag_1course-v1:QA858+TAGS+2026Regression checks: row order, moves, cycles, depth, and messages
tag_2undertag_3without any renamestag_2to the root first and names the previous parent explicitlytag_6is undertag_5UI checks in the Studio import wizard
Existing automated tests (AC 4)
TC-22 is covered by CI on #877. All checks pass: tests (django52), quality, docs, and package.