Report children on a hierarchy attach - #10489
Conversation
62941ae to
901a1a5
Compare
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
Re-trigger cubic
A hierarchical schema declares `parent` and `children` under one identifier, `parent__child`. The peer changelog looked the other side of the edge up by identifier alone and kept the first match, which is `parent`. So attaching a child told its parent that its own `parent` had become the child, and the real change on `children` was never announced. Every consumer of node mutation events saw the wrong relationship. A computed attribute whose query reads `children` filters events on the fields it reads, so it dropped the mislabelled event and never recomputed. Before 1.11.0 the same wrong event still matched, because the trigger carried no field filter at all. Resolve the peer side by the mirrored direction instead: `parent` is outbound, so it maps to the inbound `children`. A pair that holds one relationship per identifier on each side keeps its current behaviour. When the direction resolves nothing, report every candidate rather than guess one. Fixes #10485
901a1a5 to
b5e97d3
Compare
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Fixes hierarchical attach/detach changelogs so the peer is told its children relationship moved instead of its own parent, with a component test pinning the corrected behavior. The change is bounded to peer-relationship resolution and covered by a failing-before test.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 6 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Fixes hierarchy changelogs so attach/detach report the peer's mirrored children/parent and middle-node deletes report both sides, with tests pinning the corrected behavior. Bounded bug fix confined to relationship-changelog resolution.
Re-trigger cubic
211b020 to
96efefc
Compare
Both sides of a hierarchy share one identifier, so the peer side of an edge cannot be resolved by identifier alone. Three defects followed from that. The mapper that builds a deleted node's relationship changelog was keyed on the identifier, so the second hierarchy edge reused the first edge's mapper and overwrote it. A node losing a parent and a child reported one `parent` entry that pointed at the child. Key the mapper on the resolved relationship instead. A cardinality-one peer that moved described its previous peer with the new peer's schema, so the relationship named for the old peer could be one it does not declare. Resolve the removed side from the previous peer kind, as the removal branch already does. An unresolvable peer side is reported whole rather than guessed, and now always logs. The warning used to fire only for two or more candidates, which left the single wrong-direction candidate silent even though that is the case that guesses. Also record the shared-identifier rule in the schema knowledge page, and correct two rows that stated the opposite.
467be87 to
9853c40
Compare
|
|
||
|
|
||
| # A generic whose two members name their side of `shared__link` differently. | ||
| DIFFERING_PEER_NAMES: dict[str, Any] = { |
There was a problem hiding this comment.
Very specific schema we don't have anywhere else, hence being inlined here.
| # A hierarchical node whose own children relationship uses a different identifier, so it holds | ||
| # only one side under `parent__child`. |
There was a problem hiding this comment.
do we actually allow this?
There was a problem hiding this comment.
Maybe not on purpose, but yes. If a node inherits a hierarchy but declares its own children with a different identifier, add_hierarchy_node skips generating children, so the node keeps only parent under parent__child. I checked it against a real registered schema and validation accepts it, and peer_relationships then returns that single non-mirroring parent. I made the comment say how the shape arises, since it was not obvious from the test alone.
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Why
A hierarchical schema declares
parentandchildrenunder one identifier,parent__child. The peer changelog looked the other side of the edge up by identifier alone and kept the first match, which isparent. Attaching a child told its parent that its ownparenthad become the child, and the real change onchildrenwas never announced.Every consumer of node events saw the wrong relationship. A computed attribute whose query reads
childrenfilters events on the fields it reads, so it dropped the event and never recomputed. A user action rule matchingchildrennever fired.Closes #10485
Scope against the issue
The issue lists three scenarios. This PR fixes the first one. The other two need no change.
parentat the node. Fixed and tested.Update(data: {children: [...]})from the parent side. Already worked. The primary changelog names that relationship directly, so it was never ambiguous. I verified the secondary changelog is identical before and after this change, and added a test to hold it.infrahub.field.nameto the fields the transform reads.What changed
children, with the right cardinality.parentis outbound, so it maps to the inboundchildren.parententry pointing at its own child.Merge and rebase were never affected.
core/diff/query_parser.pyalready disambiguates the same way, so this follows an established pattern rather than a new one.RelationshipAddandRelationshipRemoveshare the fixed function.How to review
Start with
peer_relationshipsinbackend/infrahub/core/changelog/models.py, then the mapper key inbackend/infrahub/core/query/relationship.py.The fallback deserves the most attention. When no candidate mirrors the local direction, every candidate is returned, and the result is a guess. Two schemas reach it, both accepted by validation:
parent__childidentifier with the defaultbidirectionaldirection. Validation only checks the peers the hierarchy pair itself declares, so it never sees this one. Both entries produced are schema-invalid: the changelog names apeer_kindthe relationship does not allow.childrenunder a different identifier, so it holds onlyparentunderparent__child. The lone candidate does not mirror, and reporting it reproduces the original bug in a narrow shape.Returning nothing instead would drop a real event, which is the failure this PR fixes, so the branch keeps every candidate and always logs a warning naming the peer kind, the identifier, the direction and the candidates. A user action rule on a falsely reported name still runs its generator, so that log line is the signal to alert on. Two unit params pin both shapes.
Deciding whether
validate_identifiersshould reject these schemas outright would make the branch dead code. That is a schema-validation change with its own compatibility risk, so it is not in this PR.How to test
The hierarchy tests fail on the parent commit and pass here. Validated on release-1.10 as well: it sends the same wrong event, and only worked because the trigger carried no field filter before 1.11.0.
Impact & rollout
Checklist