Skip to content

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

Open
nattynerdy wants to merge 4 commits into
openedx:mainfrom
nattynerdy:neuley/892-tag-features-into-main
Open

nattynerdy wants to merge 4 commits into
openedx:mainfrom
nattynerdy:neuley/892-tag-features-into-main

Conversation

@nattynerdy

@nattynerdy nattynerdy commented Nov 19, 2026 •

Copy link
Copy Markdown

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

Summary by CodeRabbit

Summary

  • Bug Fixes
    • Parent-cycle errors now identify the affected input row, including cycles involving newly created or renamed tags.
    • Each detected cycle is reported once, at its earliest input row, rather than generating redundant unknown-parent errors for rows in the cycle.
    • Unknown-parent errors outside cycles continue to identify each affected row, and unrelated parent errors remain visible alongside cycle errors.

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 19, 2026
@openedx-webhooks

openedx-webhooks commented Nov 19, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @nattynerdy!

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.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Parent-cycle validation now records all input rows involved, including cycles among new tags. Parent errors identify source rows, and cycle members do not also receive unknown-parent errors.

Changes: Tag import parent validation

Layer / File(s) Summary
Record and report parent cycles
src/openedx_tagging/import_export/import_plan.py, src/openedx_tagging/import_export/exceptions.py, tests/openedx_tagging/import_export/test_api.py, tests/openedx_tagging/import_export/test_import_plan.py
The import plan records every input row in a detected cycle, including cycles involving only new tags. Tests cover cycle shapes, separate cycles, and interactions with other parent errors.
Attribute parent errors to input rows
src/openedx_tagging/import_export/actions.py, tests/openedx_tagging/import_export/test_actions.py, tests/openedx_tagging/import_export/test_api.py, tests/openedx_tagging/import_export/test_import_plan.py
Unknown-parent errors include the source row number. Cycle rows do not receive an additional unknown-parent error. Tests cover errors across action types and unrelated unknown parents.

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

Change: Bug fix

Possibly related issues

  • openedx/openedx-core#893: This issue adds a check for parent IDs that name tags deleted by the import. It concerns the same parent-validation path, but this PR does not implement that check.

Possibly related PRs

  • openedx/openedx-core#951: This PR changes the same parent-error row attribution and cycle reporting behavior, with overlapping import-plan changes.

Suggested reviewers: ufedaseyeuconsultant, chrischv

Merge Risk: Minimal · up to 6306a

This change adds row numbers to unknown-parent errors in the tag import. It also reports each parent cycle once, including cycles among new tags, and no longer adds duplicate unknown-parent errors for rows on a cycle. No concrete code risk was found. The signed contributor agreement still has to be resolved before merge.

Security architecture risk: Minimal · up to 6306a

Invalid parent cycles are reported more clearly and still prevent the import from changing the taxonomy. No new security or failure-containment risk was identified in this change.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Directly linked issue #892 has these coding requirements: (1) prefix unknown-parent and stale-parent errors with the source data row (Row N); (2) report each parent cycle, including new-only and ren… Provide readable evidence of TagImportPlan._validate_hierarchy at the reviewed head, or a diff of import_plan.py against the merge base. Confirm that: the walk reports each cycle that has a file row once, on the first row in file order;…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Tag import parent errors row and cycles (#892)" matches the main change. The PR adds row-number prefixes to unknown-parent errors and reports parent cycles once, on the cycle's first row. T…
Out of Scope Changes check Passed All changed files relate to #892. actions.py changes the parent error text and the cycle-row suppression. import_plan.py changes the cycle reporting that #892 requires. exceptions.py changes onl…
Full details: Title check

Explanation

The title "Tag import parent errors row and cycles (#892)" matches the main change. The PR adds row-number prefixes to unknown-parent errors and reports parent cycles once, on the cycle's first row. The title is terse and the phrasing is awkward, but it names the real focus of the changeset. The raw summary and objectives both confirm these changes.

Full details: Out of Scope Changes check

Explanation

All changed files relate to #892. actions.py changes the parent error text and the cycle-row suppression. import_plan.py changes the cycle reporting that #892 requires. exceptions.py changes only the ParentCycleError docstring, which the PR says now points to the correct validation method. The test files cover the #892 scenarios. The PR description excludes duplicate-value errors and the deleted-tag parent check (#893), and the reviewed actions.py diff contains no change to those areas. No unrelated change was found in the inspected diff. The import_plan.py hunks were not read, so this verdict covers the files that were read and the PR's stated scope.

Full details: Linked Issues check

Explanation

Directly linked issue #892 has these coding requirements: (1) prefix unknown-parent and stale-parent errors with the source data row (Row N); (2) report each parent cycle, including new-only and renamed-tag cycles, as one error on the first row in file order; (3) do not also report cycle rows as unknown-parent; (4) keep unrelated missing-parent and stale-parent errors; (5) keep the import_tags signature and return value.

Verified in the diff of src/openedx_tagging/import_export/actions.py (merge base to head): ImportAction._validate_parent now applies the Row {row}: prefix once, at a single return, to both the stale-parent (renamed-parent) error and the unknown-parent error. For the unknown-parent branch, a row whose self.row is in indexed_actions["_rows_on_a_cycle"] returns None, which meets requirement (3). The stale-parent branch returns before that check, so stale-parent errors on cycle rows remain reported, which meets requirement (4) for that case.

Not verified: the TagImportPlan._validate_hierarchy change in src/openedx_tagging/import_export/import_plan.py. The file diff failed, and the file read at head was truncated before _validate_hierarchy. I could not confirm that the cycle walk reports each cycle once on its first row, includes new-only and renamed-tag cycles, or populates _rows_on_a_cycle. The new tests in test_api.py, test_import_plan.py and test_actions.py were not read. The PR description and AI summary describe this behavior, but they do not establish it.

Resolution

Provide readable evidence of TagImportPlan._validate_hierarchy at the reviewed head, or a diff of import_plan.py against the merge base. Confirm that: the walk reports each cycle that has a file row once, on the first row in file order; it covers cycles of only new or renamed tags; it fills indexed_actions["_rows_on_a_cycle"] before per-row actions are validated; and the import_tags signature and return value are unchanged. Reading the test cases for these scenarios would also help.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • 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: ccb4dc2a-d085-4a6d-8b52-a7a378aae42d
Commits

Reviewing files that changed from the base of the PR and between 0e88e20 and 6306a6d.

Files selected for processing: 6

  • src/openedx_tagging/import_export/actions.py
  • src/openedx_tagging/import_export/exceptions.py
  • src/openedx_tagging/import_export/import_plan.py
  • tests/openedx_tagging/import_export/test_actions.py
  • tests/openedx_tagging/import_export/test_api.py
  • tests/openedx_tagging/import_export/test_import_plan.py
Files skipped from review as they are similar to previous changes: 1

  • src/openedx_tagging/import_export/exceptions.py

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

@nattynerdy nattynerdy changed the title 892 tag features into main Tag import parent errors row and cycles (#892) Nov 19, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Nov 24, 2026
@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs test run Author's first PR to this repository, awaiting test authorization from Axim 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

4 participants