fix: use (path, segment_code) instead of id_path as diff JOIN key - #257
fix: use (path, segment_code) instead of id_path as diff JOIN key#257hf-mrdachner wants to merge 2 commits into
Conversation
The id_path contains positional indices (@00005-00001-) that shift when segments are inserted in newer format versions, causing false added/deleted rows. (path, segment_code) is a stable, unique key across versions. Example: UTILMD/44001 FV2510→FV2604 - Before: 69 added, 64 deleted, 27 modified (160 "changes") - After: 5 added, 0 deleted, 1 modified (6 real changes) Fixes #256 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…oin key - Rename test_diff_view_no_duplicate_id_paths to test_diff_view_no_duplicate_join_keys, checking (path, segment_code) uniqueness instead of id_path - Update snapshots: significantly fewer false add/delete entries due to stable join key (snapshot file shrinks by ~2500 lines) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hf-kklein
left a comment
There was a problem hiding this comment.
I understand the problem and commented on #256 in a longer comment.
Specifically for this PR: I'd not merge it like that because we loose the only purpose that id-path has: to be unique. Instead of a single column that is unique we introduce a mechanism that requires the users of the DB to think and interpret themselves. The intention of the pre-computed ID path was to obey the "don't make me think" principle. The users of the DB shouldn't solve the uniqueness problem on their own but build upon guarantees that we as creators of the DB give and enforce.
Can we keep the id-path as a SINGLE column that is unique per ahb-line (together with formatversion and prüfi)? I like that it's a SINGLE column, not a tuple of columns. But this also means you have to dig deeper into the code and parts of the code I'm not proud of ;)
| Test that there are no duplicate (path, segment_code) pairs for the same version pair comparison. | ||
| Each (path, segment_code) combination should appear exactly once in the diff results. |
There was a problem hiding this comment.
this is why I wouldn't merge the PR as of now: if the id is not unique anymore we can drop it right away. that's the only (and a very important) purpose of the id_path column.
the id path MUST stay unique
|
removing the guarantees that id-path gives right now would also mean to rewrite parts of the ahb-tabellen codebase. ahb-tabellen is agnostic on how idpath looks like but it needs the guarantee that it's unique (and that sort_path has the correct order). |
|
ok, noch ein letzter kommentar: ich glaube es ist besser das "id-path ist falsch konstruiert und nicht für cross-formatversions-vergleiche zu gebrauchen" zu lösen als den vergleich symptombekämpfend anzupassen. verstehst du, was ich meine? auch wenn das schwieriger ist, wäre es glaube ich der ursächliche fix. das problem versteh ich und das ist vollkommen richtig in #256 zusammengefasst. aber die lösung sollte imho auch direkt bei der konstruktion vom id-path ansetzen |
|
Hi @hf-mrdachner! An alternative fix is now available in #260 that addresses the root cause — fixing The approach in #260 injects semantic qualifiers (like Your bug report in #256 and the edge case analysis in #258 and #259 were essential foundation work for this fix — the IFTSTA, PARTIN, MSCONS, and PRICAT cases you identified are now all tested explicitly. Please keep filing issues like these; they make the codebase better! 🙏 Would you be open to reviewing #260? Your deep understanding of the data would be very valuable for the review. |
|
Closing in favor of #260 which fixes the root cause (id_path construction) instead of working around it in the view JOIN. The remaining MSCONS cross-version instability is a data quality issue tracked in xml-migs-and-ahbs#80. |
Summary
id_pathwith(path, segment_code)as the JOIN key inv_ahb_diffid_pathcontains positional indices that shift on insertions, producing false add/delete pairs(path, segment_code)is unique per pruefidentifikator+version and stable across versionsImpact
Example: UTILMD/44001 FV2510→FV2604
Test plan
test_ahb_diff_view.pytests — 7/7 passed(path, segment_code)uniqueness — unique for 97% of (version, pruefi) combinationsKnown limitations
pathis not unique enough due to flat segment group naming — tracked in IFTSTA: path column not unique enough for stable diff JOIN key #258Fixes #256
🤖 Generated with Claude Code