Repository navigation
OpenConceptLab/ocl_online#687 | Seeded versions link codes that have two HEAD rows; a source version's export lists only its own hierarchy - #1037
Conversation
…two HEAD rows; a source version's export lists only its own hierarchy - Concept.get_versioned_objects_by_uri resolves a URL several versioned objects share to the lowest id, the row the importers' .first() lookups write to, so a seed's hierarchy step links the version rows the import wrote. - A source version's export (not HEAD, not a collection) lists each row's own links only: parents of its source as the version's row of them, children only when they are the version's rows. HEAD's links no longer leak into older versions' exports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt
…children by concept, members only in version exports - ImportHierarchy.resolve_parents resolves a URL naming a version of a code with two versioned objects to the one get_versioned_objects_by_uri resolves the code's URL to (F1.1). - A source version's export lists as children the version's rows that link to any row of the concept, as get_version_hierarchy_queryset does, not only those linking to the exported row (F1.2), and lists only the version's own rows as parents and children, never another source's (F1.3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt
Codex review, pass 1 (codex-cli 0.169.0, commit 22a2d83)Verdict: 3 findings, all P1. All three reproduced as failing tests on 22a2d83 and are fixed in the next commit.
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "full",
"commit": "22a2d83a",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "F1.1",
"severity": "P1",
"tag": null,
"file": "core/concepts/models.py",
"line": 1545,
"claim": "A versioned parent URL can still send a seed's hierarchy link to the duplicate that the seed drops.",
"scenario": "Two HEAD rows share code P. A seed imports P and C, and C's parent URL names a revision of the higher-ID P. The concept importer writes under the lower-ID P, but ImportHierarchy.resolve_parents bypasses the changed lookup for versioned URLs. It links C to the higher-ID P, which the seed then drops from membership. The seeded version's C /parents/ omits P and its P /children/ omits C.",
"action": "For same-source parents in a seed, validate the referenced revision and resolve its code to the concept lineage the seed actually imported. Add a duplicate-parent test that supplies a versioned parent URL.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.2",
"severity": "P1",
"tag": null,
"file": "core/concepts/serializers.py",
"line": 681,
"claim": "The export omits children whose links point to an older revision of the exported parent.",
"scenario": "A regular bulk import renames parent P without updating child C, then a source version captures the new P revision and the unchanged C revision. C still links to the older P revision. The export maps C's parent URL to the new P revision, but P's child list is empty because it reads reverse links to that exact row. The version's /children/ endpoint returns C because it matches the parent's versioned object.",
"action": "Resolve children in batches from the source version's member rows, matching each stored parent link by versioned object as /children/ does. Test a release created after a parent-only update.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.3",
"severity": "P1",
"tag": null,
"file": "core/concepts/serializers.py",
"line": 711,
"claim": "A source version's export can include a public child from another source's HEAD, and that link can disappear after a later import.",
"scenario": "Source A's v1 contains a revision of P. A seed of public source B makes C a child of P and links both C's HEAD and its revision to P. A's v1 export lists those out-of-version URLs. When a later B seed moves C to another parent, it removes C's HEAD link from P, changing A's v1 export.",
"action": "Require source-version hierarchy URLs to resolve to members of the exported version. Keep the existing cross-source handling for HEAD and collection exports. Add a cross-source move case to the export test.",
"lines_delta": null,
"confidence": "high"
}
]
}Responses (fixed in dbf6358; each new test failed on 22a2d83 and passes now):
|
…sions, active rows and every member row in version exports - ImportHierarchy.resolve_parents redirects a URL naming a version of a duplicated code only in a seed (from_uri_map seed=True, from reconcile_import_hierarchy's replace_head); make_hierarchy and ordinary imports keep the version a URL names (F2.1). - A source version's export links only its active member rows (F2.4), and every member row of a parent concept (F2.5). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt
Codex review, pass 2 (codex-cli 0.169.0, commit dbf6358)Verdict: pass 1's F1.3 resolved. F1.1 and F1.2 marked regressed, with 5 new findings: 2 P1, 3 P2.
Responses (c0d1ae6; each new test failed on dbf6358 and passes now):
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "verify",
"commit": "dbf63587",
"verdict": "findings",
"prior": [
{
"id": "F1.1",
"status": "regressed"
},
{
"id": "F1.2",
"status": "regressed"
},
{
"id": "F1.3",
"status": "resolved"
}
],
"findings": [
{
"id": "F2.1",
"severity": "P1",
"tag": null,
"file": "core/concepts/models.py",
"line": 2152,
"claim": "The shared resolver redirects explicit parent version URLs in hierarchy repairs.",
"scenario": "An administrator repairs a historical child's hierarchy using the version URL of the higher-ID duplicate parent. The repair now links the child to the lower-ID parent's latest row, so the intended parent still has no child and another parent gains one.",
"action": "Scope duplicate canonicalization of explicit version URLs to seed reconciliation. Preserve the named version's concept identity for hierarchy repairs and ordinary imports, and test the repair path with a duplicate parent.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.2",
"severity": "P1",
"tag": null,
"file": "core/common/mixins.py",
"line": 1327,
"claim": "Existing source-version downloads keep serving the old hierarchy.",
"scenario": "A version already has a ZIP containing HEAD links when the fix deploys. GET still redirects to that ZIP, and a normal export POST reuses it. Users continue to download the incorrect hierarchy until a forced rebuild.",
"action": "Regenerate affected stored archives during rollout or invalidate them so normal export requests rebuild them. Verify an existing version through the download endpoint.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.3",
"severity": "P2",
"tag": null,
"file": "core/concepts/models.py",
"line": 2188,
"claim": "A seed can add a parent link to a concept row already in a prior release.",
"scenario": "A legacy v1 contains both rows for P, and C links to the higher-ID P. With duplicate-version prevention enabled, a v2 seed resubmits unchanged C with the same explicit parent URL. The hierarchy change check compares versionless URLs and reuses C's v1 row. Reconciliation adds the lower-ID P link to that row, so a regenerated v1 export now shows C under both parents.",
"action": "Compare resolved parent concept identities before reusing a concept row. Create a new child row when canonicalization changes its parent identity, and compare the v1 export before and after that seed.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.4",
"severity": "P2",
"tag": null,
"file": "core/concepts/serializers.py",
"line": 682,
"claim": "The hierarchy queries can emit URLs for soft-deleted rows omitted from the export.",
"scenario": "In v2, C links to an older row of P. An administrator soft-deletes C's version row, leaving its source membership intact. The archive omits C from its concepts, but the new child lookup still lists C under P. The parent lookup can likewise select an inactive member row.",
"action": "Apply the export's active-row filter to both parent and child membership queries. Add a regression test that verifies hierarchy URLs refer to rows present in the archive.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.5",
"severity": "P2",
"tag": null,
"file": "core/concepts/serializers.py",
"line": 680,
"claim": "The export drops parent rows when a legacy source version contains multiple rows of one parent concept.",
"scenario": "An older race left two rows of P flagged latest, and a source version copied both into its membership. For a child linked to P, the version API returns both member rows. The export's parent dictionary keeps only the higher-ID row, while both parent rows can still list the child.",
"action": "Retain all eligible member URLs per parent identity, and test an export of a source version that contains both rows.",
"lines_delta": null,
"confidence": "high"
}
]
} |
…ersions of the codes it imports ImportHierarchy.resolve_parents takes the seed's concept URLs and redirects a URL naming a version of a duplicated code only when the seed imports that code; a parent outside the import keeps the version its URL names (F3.1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt
Codex review, pass 3 (codex-cli 0.169.0, commit c0d1ae6)Verdict: every P1 resolved. F2.2 (handled as a deploy step) and F2.3 (accepted) are still open. Two new P2s. Prior: F1.1 resolved, F1.2 resolved, F1.3 resolved, F2.1 resolved, F2.2 unresolved, F2.3 unresolved, F2.4 resolved, F2.5 resolved
Responses:
No P0 or P1 is open after 3 passes, so the loop stops here. A Codex check of the commits after c0d1ae6 follows. findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "verify",
"commit": "c0d1ae64",
"verdict": "findings",
"prior": [
{
"id": "F1.1",
"status": "resolved"
},
{
"id": "F1.2",
"status": "resolved"
},
{
"id": "F1.3",
"status": "resolved"
},
{
"id": "F2.1",
"status": "resolved"
},
{
"id": "F2.2",
"status": "unresolved"
},
{
"id": "F2.3",
"status": "unresolved"
},
{
"id": "F2.4",
"status": "resolved"
},
{
"id": "F2.5",
"status": "resolved"
}
],
"findings": [
{
"id": "F3.1",
"severity": "P2",
"tag": null,
"file": "core/concepts/models.py",
"line": 2154,
"claim": "A seed redirects explicit parent version URLs even when the parent is outside the source being seeded.",
"scenario": "A seed of source A imports child C with a parent URL naming a revision of the higher-ID duplicate P in source B. Both P rows are active and have different names. The seed links C to the lower-ID P, and C's HEAD /parents/ returns that row's UUID and name. Source B was untouched by the seed.",
"action": "Apply duplicate resolution to parent codes the seed imports. Preserve the lineage named by explicit version URLs for other parents.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F3.2",
"severity": "P2",
"tag": null,
"file": "core/concepts/models.py",
"line": 2198,
"claim": "The historical export change in F2.3 can occur when the prior release holds only one of the duplicate parents.",
"scenario": "A legacy v1 holds the lower-ID P and a revision of C whose stored link points to the higher-ID P outside v1. With duplicate-version prevention enabled and C's pre-reconciliation checksum still stored, an unchanged v2 seed can reuse C's v1 row. Reconciliation adds the lower-ID P link to that shared row. A v1 export generated before v2 shows no C\u2013P link, and a rebuild after v2 shows the link in both directions.",
"action": "Compare resolved parent lineages before reusing a published child row. Create a new child revision when reconciliation would change its links, and test a prior release containing only the lower-ID parent.",
"lines_delta": null,
"confidence": "high"
}
]
} |
…map reads a concept id as the importer does Concept.get_import_hierarchy_map reads a line's id as a string, as ConceptImporter does, so a numeric 0 is the code '0' and a seed redirects a version of it like any other code it imports (FC.1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt
Codex check of commits c0d1ae6..b5effed (codex-cli 0.169.0)Verdict: one P2, fixed in c0c9360.
Response:
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "b5effeda",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "FC.1",
"severity": "P2",
"tag": null,
"file": "core/concepts/models.py",
"line": 2152,
"claim": "A seed can lose a parent link when it imports duplicate code `0` with a numeric JSON ID.",
"scenario": "A source has two HEAD rows for code `0`. The seed imports the parent with `\"id\": 0` and child C with a parent URL naming a revision of the higher-ID duplicate. The concept importer keeps the lower-ID row, but the hierarchy map skips the falsy numeric ID. The resolver links C to the higher-ID duplicate, which the seed drops. The new version's `/parents/` and export omit C's link to `0`. The previous resolver linked C to the retained row.",
"action": "Treat numeric `0` as a supplied ID and convert it to a string before building the hierarchy map. Add a seed test with duplicate code `0` and an explicit parent version URL.",
"lines_delta": null,
"confidence": "high"
}
]
} |
…mport would apply a rejected numeric-0 row's links This reverts commit c0c9360. Reading a numeric id 0 into the hierarchy map also makes an ordinary parallel import add a rejected row's parent links (FC.2), which applies to other ids already and is outside this fix. FC.1, a seed of a duplicated code 0 with a versioned parent URL, is accepted as a P2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt
Codex check of commits b5effed..c0c9360 (codex-cli 0.169.0)Verdict: one P1, caused by c0c9360. That commit is reverted in ccbed33, so the PR's code is again exactly what the check of b5effed reviewed.
Response:
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "c0c93609",
"verdict": "findings",
"prior": [
{
"id": "FC.1",
"status": "regressed"
}
],
"findings": [
{
"id": "FC.2",
"severity": "P1",
"tag": null,
"file": "core/concepts/models.py",
"line": 1521,
"claim": "The numeric ID fix lets ordinary parallel imports add parent links from rejected concept rows.",
"scenario": "A source already contains code `0` and a parent `P`. Submit a parallel import with `update_if_exists=false` and a row with numeric `id: 0` that names `P` as a parent. The worker rejects the row because `0` already exists, but the final hierarchy reconciliation adds the link to `P`. Before this commit, the hierarchy map skipped that row.",
"action": "Keep numeric ID normalization for isolated seeds and restrict ordinary parallel hierarchy reconciliation to concept rows accepted by the workers. Add a regression test that checks the existing concept's parents after the rejected import.",
"lines_delta": null,
"confidence": "high"
}
]
} |
Simplification review (fresh Claude subagent, Sonnet 5.5, commit ccbed33)Verdict: the PR is already tight. There's no dead code and no single-caller layers to cut. Four small items were found, and I'm not applying any of them. Each would need another review and CI round before tomorrow's deploy, for no change in behaviour.
No commits after this review, so no further Codex check is needed. simplify.json{"perspective":"simplify","mode":"full","reviewer":"claude subagent (sonnet)","commit":"ccbed330","verdict":"findings","findings":[{"id":"S1","tag":"dup-test","file":"core/importers/tests.py","line":6833,"claim":"Final per-concept loop in test_version_export_links_every_row_it_holds_and_no_other repeats the exported-set check and C's parent_concept_urls equality.","action":"nothing replaces it","lines_delta":-2,"confidence":"medium"},{"id":"S2","tag":"dup-test","file":"core/importers/tests.py","line":6732,"claim":"sorted(child.parent_concept_urls) == ['.../Q/'] repeats the version_hierarchy(child,'parent_concepts','v1') assertion's intent.","action":"nothing replaces it","lines_delta":-2,"confidence":"low"},{"id":"S3","tag":"shrink","file":"core/concepts/serializers.py","line":693,"claim":"get_shared_hierarchy_urls and get_version_hierarchy docstrings restate Concept.get_version_hierarchy_queryset's rules.","action":"Keep one sentence pointing at get_version_hierarchy_queryset.","lines_delta":-6,"confidence":"medium"},{"id":"S4","tag":"shrink","file":"core/concepts/models.py","line":2137,"claim":"Seed explanation duplicated across from_uri_map and resolve_parents docstrings; pylint disable may be avoidable.","action":"Keep the explanation on resolve_parents only.","lines_delta":-3,"confidence":"low"}]} |
snyaggarwal
left a comment
There was a problem hiding this comment.
Quick review: looks right, and nothing blocks the merge.
- Seeding links the rows it wrote.
get_versioned_objects_by_urinow takes the lowest id, the row the importers'.first()lookups update, so a code with two HEAD rows gets its parents on the row the seed wrote.resolve_parentsredirects a named version only for codes in the seed (seed=replace_head, which only the version commit passes). The admin repair (make_hierarchy) still resolves a named version exactly, and the test covers that. - The export reads the version's own hierarchy. The serializer's two call sites already use
self., so the switch away from@staticmethodis safe. Collection and HEAD exports keep the old path. - Behaviour change worth stating in the release notes: a source version's export now lists only the version's own rows as parents and children. A parent in another (public) source, which the old union included, is left out. That matches the version API.
- Existing exports keep the old hierarchy until rebuilt with
?force=true, as you note. Staging's 2.82 is deleted and reloaded anyway.
🤖 Review by Claude Code
TL;DR: fixes wrong parents in seeded source versions and in their exports. A seed now links each code's new version to its parents in that version, even when the code or its parent has two HEAD rows. A source version's export lists only that version's own links. For OpenConceptLab/ocl_online#687.
What was wrong
LOINC 2.82 was seeded on staging, and for 4,178 concepts its
/parents/was empty or wrong (for example,GET …/LOINC/2.82/concepts/3282-1/parents/returns[]). There are two causes.1. Codes with two HEAD rows.
ConceptImporter.get_queryset().first()orders by primary key.Concept.get_versioned_objects_by_uri. That builds a dict from an unordered query, so the last row read won.2. A version export added HEAD's links to every row (ocl_online#687).
ConceptVersionExportSerializer.get_shared_hierarchy_urlsadded the versioned object's links whether or not the row was still the latest, and it listed the linked rows as they were. So:The version API doesn't do this.
get_version_hierarchy_querysetreads only the version row's own links and maps them to the version's members.Changes
core/concepts/models.pyget_versioned_objects_by_uriresolves a URL that several versioned objects share to the lowest id, the same row the importers'.first()lookups write to. In a seed, a parent URL that names a version of such a code, when the seed imports that code, resolves the same way (ImportHierarchy.resolve_parents).make_hierarchyand ordinary imports keep the version a URL names. Every import's hierarchy step uses it, along withmake_hierarchyand the large-drop guard's mapping matcher.core/concepts/serializers.py,core/common/utils.pyget_version_hierarchy_queryset, which the version API uses. Its parents are the row's own parent links, given as the version's rows of those concepts. Its children are the version's rows that link to any row of the concept. Only the version's active rows (the rows the export holds) are listed, every one of them where a concept has more than one. HEAD's links are never listed, and neither are concepts outside the version, such as other sources'. HEAD and collection exports are unchanged.Tests
In
core/importers/tests.py(IsolatedVersionImportTest):test_isolated_import_links_codes_that_have_two_head_rows: a seed where both a child and a parent have a second, retired HEAD row, plus a child whose parent URL names a version of the duplicate. v2's/parents/and/children/follow the file, and v1 keeps its parent. Fails on master: v2 lists no parent.test_version_export_lists_only_its_own_hierarchy: v1's export is the same before and after v2 moves a child and another source's public concept links to v1's parent. v2's export lists only v2's links. Fails on master: v1's export lists both parents, plus HEAD rows as children.test_isolated_import_keeps_the_version_a_url_names_outside_the_import: a seed whose parent URL names a version of a duplicated concept in another source keeps that version.test_hierarchy_repair_keeps_the_version_a_url_names:make_hierarchywith a URL naming a version of the higher-id duplicate links that duplicate.test_version_export_links_every_row_it_holds_and_no_other: a version with an inactive member row and two rows of one parent concept. Every hierarchy URL is a row the export holds, and the child lists both parent rows.test_version_export_lists_children_that_link_an_older_row_of_their_parent: a release made after an ordinary import changes only the parent still lists the unchanged child under it, as the version API does.Queries
A source version's export adds two queries per batch of 1,000 concepts, and no longer prefetches child links or HEAD's links. EXPLAIN on production (no ANALYZE), with LOINC 2.81:
versioned_object_idindex andconcepts_sources_source_concept_idx.concepts_hierarchicalconcepts, 1.8M rows sequentially scanned, against the batch's concept rows through theversioned_object_idindex;concepts_sources_source_concept_idxandconcepts_pkey;For 2.82 that's about 250 batches, against an export that runs about two hours.
After deploy
POST <version>/export/?force=true./parents/should then match the file, and its export should have no parent-link differences.15783-4 16082-0 21609-3 82003-5 interRAI LP376481-0 LP376482-8 LP40216-1 LP420186-1 LP6767-0 LP71348-4.2.71.21AAhave links only through HEAD. Their export now lists no parent for them, which matches what the version API already returns. 2.81 has 12 such rows.Related
oclapi2#1021 (ocl_issues#3059) changes
ConceptChildrenViewandConceptParentsView. This PR doesn't touch them. It changes the importer's hierarchy step and the export, so the two don't overlap.Checklist
core.importers,core.concepts,core.common.testsandcore.integration_teststests_sources,tests_collections,tests_cross_repo_accessandtests_concepts. Pylint 4.0.9 exits 0 on the changed files. (ConceptPropertyFilterViewTestfails on a stale local search index and passes once it's recreated, as on master.)🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qWFxV2q74bjstFDfjt