Skip to content

Tag import parent errors row and cycles (#892) - #925

Open
ufedaseyeuconsultant wants to merge 3 commits into
openedx:mainfrom
ufedaseyeuconsultant:ufedaseyeu/892-tag-import-parent-errors-row-and-cycles
Open

ufedaseyeuconsultant wants to merge 3 commits into
openedx:mainfrom
ufedaseyeuconsultant:ufedaseyeu/892-tag-import-parent-errors-row-and-cycles

Conversation

@ufedaseyeuconsultant

Copy link
Copy Markdown
Contributor

Description

Improves two parent errors that the tag import shows at the Plan step, so a Platform Administrator re-importing a competency taxonomy can fix the file in one pass.

The unknown parent error names its row. "Unknown parent tag (tag_100). Add a row for the parent to your file." now starts with Row N: , where N is the row's position among the file's data rows, counting from 1 (spreadsheet line N + 1 in a CSV). This is the same row number the stale parent error from #858 already shows. The #N that the error line starts with is the step's number in the Plan. That number counts every step in the Plan, deletes included, and rows are not built in file order, so it usually differs from the row number. ImportAction._validate_parent builds either of its two parent errors and applies the Row N: prefix once, at a single return, so the two errors cannot drift apart. Steps that no row describes, such as deletes and the moves to the root, have no row and validate no parent, so they are unaffected.

Every parent cycle is reported as a cycle. Before it builds any row's action, the plan computes the tag tree as it will be after the import and walks it to find parent cycles (TagImportPlan._validate_hierarchy). The walk reports every cycle that has a row in the file, once, on the cycle's first row: Row N's parent_id (X) creates a parent cycle. This includes a cycle made only of new tags, which the walk skipped before this change; the per-row check then reported one of its rows as an "Unknown parent tag" although the file has a row for that parent.

A row on a cycle is not also reported as an unknown parent. The plan builds each row after the row that creates its parent, so the per-row check can find the parent among the actions built so far. In a cycle whose rows all create their parents or rename existing tags to the parents' ids, no order builds every row after its parent's row, so one of them is checked before its parent exists. _validate_hierarchy records the rows of every cycle it reports in indexed_actions["_rows_on_a_cycle"], and _validate_parent returns no unknown parent error for those rows. Skipping that error hides nothing, because every parent on a cycle is a tag of the final tree and the cycle error already rejects the import. The stale parent error from #858 is still reported for a row on a cycle.

Which roles this affects: Platform Administrator, through the Studio taxonomy import wizard. Every file rejected before is still rejected; some now show fewer, clearer errors.

Supporting information

Testing instructions

  1. pytest --no-cov tests/openedx_tagging/import_export/. The acceptance scenarios are in TestImportAcceptanceScenarios in test_api.py. Each one runs as a full replace import in several row orders.
  2. Manually, in the Studio taxonomy import wizard, with a full replace import of a JSON or CSV file:
    • In a taxonomy with tags the file omits, give the fourth row parent_id tag_100, with no row and no tag tag_100. The Plan step shows Row 4: Unknown parent tag (tag_100). Add a row for the parent to your file., and its step number #N is different from 4.
    • Into an empty taxonomy, import new_a with parent_id new_b and new_b with parent_id new_a. The Plan step shows exactly one error, Row 1's parent_id (new_b) creates a parent cycle., and no "Unknown parent tag" error.
    • Add a third row, new_q with parent_id tag_100. The Plan step shows the cycle error and Row 3: Unknown parent tag (tag_100). ....

Other information

  • import_tags keeps its signature and return value. No migration.
  • A separate docs: commit corrects the ParentCycleError docstring: it said the row is 1-based "as in DuplicateFinalIdError", whose docstring does not state that. It now points at TagImportPlan._validate_no_duplicate_final_ids, which does.
  • Out of scope: the duplicate value errors, which also name no row, and the check for a parent_id that names a tag the import deletes ([Follow-up BE] Tag import: reject a parent_id that names a tag the full replace import deletes #893).
  • Open product question, not blocking this PR: a parent cycle is reported by one error that names only the cycle's first row, as the acceptance criteria require. Changing any one row's parent breaks the cycle, so that row is enough to make the file import. An administrator whose intended fix is on another row of a long cycle still has to trace the parent_id values by hand. Listing every row of the cycle in the error would change the acceptance criteria text, so it would need its own ticket.

🤖 Generated with Claude Code

ufedaseyeuconsultant and others added 3 commits November 2, 2026 23:25
The unknown parent error at the Plan step named no row. Its only
locator was the step number #N, which counts every step in the Plan,
deletes included, and rows are not built in file order, so #N usually
differs from the row. An administrator could not tell which row to fix,
or tell apart several rows naming the same missing parent.

ImportAction._validate_parent now builds either of its two parent
errors, the stale parent error from openedx#858 or the unknown parent error,
and adds the "Row N: " prefix once, at a single return. Steps that no
row describes have no row and keep the unprefixed text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TagImportPlan._validate_hierarchy skipped a parent cycle made only of
new tags. The per-row check then reported one of its rows as an
"Unknown parent tag", although the file has a row for that parent.

The hierarchy walk now reports every cycle that has a row in the file,
once, on the cycle's first row. It records the 1-based rows of each
reported cycle in indexed_actions["_rows_on_a_cycle"], and
_validate_parent returns no unknown parent error for those rows, since
every parent on a cycle is a tag of the final tree. The stale parent
error is still reported for a row on a cycle. _validate_hierarchy drops
its pk_of parameter, which nothing in it reads any more.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The ParentCycleError docstring said its row is 1-based "as in
DuplicateFinalIdError", but that class's docstring does not state the
convention. TagImportPlan._validate_no_duplicate_final_ids does, so the
note now points there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 3, 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.

@ufedaseyeuconsultant

Copy link
Copy Markdown
Contributor Author

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: Ready for Review

Development

Successfully merging this pull request may close these issues.

[Follow-up BE] Tag import: parent errors name their row and report every cycle as a cycle

2 participants