fix: pass SchemaBranch when parsing constraint paths in HFID derivation#9322
Conversation
_derive_human_friendly_id was passing the NodeSchema as the `schema` argument to parse_schema_path, but that parameter is treated as a SchemaBranch (the function calls .get(name=..., duplicate=True) on it). With a single-element relationship-only uniqueness_constraint (e.g. [["parent"]]), the relationship branch runs and crashes with AttributeError: 'NodeSchema' object has no attribute 'get'. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. This is a one-line fix that passes the correct argument (SchemaBranch) to parse_schema_path, resolving a crash for single-element relationship-only uniqueness constraints without changing any logic, API, or database schema, and includes a comprehensive unit test that fails on the original code.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Shadow auto-approve: would auto-approve. This one-line fix corrects a typo where the wrong schema object was passed to parse_schema_path, resolving a crash for single-element relationship-only uniqueness constraints without affecting existing behavior, and it includes a targeted test that validates the fix.
Re-trigger cubic
ajtmccarty
left a comment
There was a problem hiding this comment.
hopefully this isn't too offensive, but I pushed two commits to your branch to add a fixture (that can be used in other unit tests) and call process() on SchemaBranch instead of just some of the methods that process() calls. I thought it would be easier than describing the changes, but I can do that in the future if you'd prefer
Why
Creating a node with a single-element relationship-only
uniqueness_constraintsentry (e.g.[["parent"]]) crashes schema processing withAttributeError: 'NodeSchema' object has no attribute 'get'and returns a 500. The docs list relationship-only constraints as supported syntax, so the implementation and docs disagree. The bug has been present since atleast 0.16.1.
Goal: Make relationship-only single-element uniqueness constraints process without crashing.
Non-goals:
schema_path.is_type_attributeis true, which a pure relationship path is not — so the constraint correctly stays as a constraint and isn't lifted to HFID).Closes #4483
What changed
Behavioral changes
uniqueness_constraints: [["<relationship>"]]with no other entries.["parent", "name__value"]were already working — that path skipped the broken branch via theif len(constraint_paths) > 1: continuefilter, which is why the bug only surfaces for the single-element relationship case.Implementation notes
_derive_human_friendly_id: passschema=self(theSchemaBranch) tonode.parse_schema_pathinstead ofschema=node.parse_schema_pathtreats itsschemaargument as aSchemaBranchand calls.get(name=..., duplicate=True)on it when resolving a relationship peer; passing theNodeSchemainstead made that call raise.parse_schema_pathcall sites in the same file already passschema=self, so this was a one-spot typo, not a systemic issue.What stayed the same
parse_schema_pathis unchanged.How to review
backend/infrahub/core/schema/schema_branch.py— the one-line fix at the_derive_human_friendly_idcall site.backend/tests/unit/core/schema/test_schema_branch.py— new test class that builds a hierarchical schema withuniqueness_constraints=[["parent"]]and assertsprocess_human_friendly_iddoes not raise. The test fails onstablewith the originalAttributeError.No risky areas — the change strictly narrows the failure surface; mixed-constraint and attribute-only paths were already exercising the correct argument.
How to test
To reproduce on
stablebefore the fix, load a schema like:Schema processing raises
AttributeError: 'NodeSchema' object has no attribute 'get'→ HTTP 500. With this PR the same schema loads cleanly.Impact & rollout
Checklist
changelog/4483.fixed.md)Summary by cubic
Fixes a crash when a node uses a single-element relationship-only
uniqueness_constraints(e.g.,[["parent"]]) by passing theSchemaBranchtoparse_schema_pathduring HFID derivation. Adds a fixture-based unit test that processes a simple Car/Person schema to verify the constraint resolves without error and does not promote to an HFID.Written for commit 8e29c5a. Summary will update on new commits. Review in cubic