Clean up of logic within Node#910
Conversation
WalkthroughSchemas (infrahub_sdk/schema/main.py) gain capability properties: supports_artifact_definition, supports_artifacts, supports_file_object, supports_hierarchy, hierarchical_relationship_schemas, and RelationshipSchemaAPI cardinality helpers. Node initialization (infrahub_sdk/node/node.py) now reads feature flags directly from those schema properties instead of inspecting subclass/type attributes. Hierarchical relationships are initialized by iterating schema.hierarchical_relationship_schemas and creating RelatedNode/RelatedNodeSync for single-cardinality or RelationshipManager/RelationshipManagerSync for many-cardinality relationships. SDK-side construction of pseudo-schemas and RelationshipKind-based wiring was removed; hierarchical entries originate from the schema. 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## infrahub-develop #910 +/- ##
====================================================
- Coverage 81.09% 81.04% -0.06%
====================================================
Files 121 121
Lines 10592 10644 +52
Branches 1581 1586 +5
====================================================
+ Hits 8590 8626 +36
- Misses 1487 1502 +15
- Partials 515 516 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 11 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@infrahub_sdk/schema/main.py`:
- Around line 344-350: The supports_artifacts and supports_file_object checks
currently live only on NodeSchemaAPI causing ProfileSchemaAPI and
TemplateSchemaAPI (which also have inherit_from) to incorrectly return False;
move these property implementations to a shared base or mixin used by
MainSchemaTypesAPI (e.g., create an InheritFromSupportMixin with
supports_artifacts and supports_file_object that check "CoreArtifactTarget" and
"CoreFileObject" in inherit_from) or alternatively implement the same properties
on ProfileSchemaAPI and TemplateSchemaAPI so they mirror NodeSchemaAPI's
behavior; update references to supports_artifacts and supports_file_object
across MainSchemaTypesAPI and node/node.py to use the new shared implementation
to avoid FeatureNotSupportedError regressions.
- Around line 352-359: supports_hierarchy uses "self.hierarchy is not None" but
hierarchical_relationship_schemas uses "if not self.hierarchy", causing
inconsistent treatment of empty-string hierarchy; update
hierarchical_relationship_schemas to use the same predicate as
supports_hierarchy (i.e., check "self.hierarchy is not None") so both
supports_hierarchy and hierarchical_relationship_schemas (and any related
_hierarchy_support logic) treat an empty string consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: de4b62fb-d38d-4b74-9fdc-36ae1126c1dc
📒 Files selected for processing (2)
infrahub_sdk/node/node.pyinfrahub_sdk/schema/main.py
ajtmccarty
left a comment
There was a problem hiding this comment.
coderabbit might have a couple legitimate comments, but, other than that, it looks great. big improvement
| GenericSchemaAPI, | ||
| ProfileSchemaAPI, | ||
| RelationshipCardinality, | ||
| RelationshipKind, | ||
| RelationshipSchemaAPI, | ||
| TemplateSchemaAPI, | ||
| ) |
@ajtmccarty, yeah the reason for the major one was to get rid of an if-statement within the Will have to check on the hierarchy thing. |
sounds good to me |
7f6ece9 to
dc28bad
Compare
Deploying infrahub-sdk-python with
|
| Latest commit: |
dc28bad
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7c189d38.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://pog-node-cleanup.infrahub-sdk-python.pages.dev |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
infrahub_sdk/schema/main.py (1)
370-383: Consider addingkind=RelationshipKind.HIERARCHYto ancestors/descendants for consistency.
parentandchildrenexplicitly setkind=RelationshipKind.HIERARCHY, butancestorsanddescendantsrely on the default (GENERIC). While functionally this may not matter (since_process_hierarchical_fieldsdetermines behavior by name rather than kind), semantically all four represent hierarchical relationships.♻️ Suggested change for semantic consistency
RelationshipSchemaAPI( - name="ancestors", peer=self.hierarchy, cardinality="many", read_only=True, optional=True + name="ancestors", peer=self.hierarchy, kind=RelationshipKind.HIERARCHY, cardinality="many", read_only=True, optional=True ), RelationshipSchemaAPI( - name="descendants", peer=self.hierarchy, cardinality="many", read_only=True, optional=True + name="descendants", peer=self.hierarchy, kind=RelationshipKind.HIERARCHY, cardinality="many", read_only=True, optional=True ),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@infrahub_sdk/schema/main.py` around lines 370 - 383, The ancestors and descendants RelationshipSchemaAPI entries currently omit kind, defaulting to GENERIC; update them to explicitly set kind=RelationshipKind.HIERARCHY for semantic consistency with parent and children. Locate the list returning RelationshipSchemaAPI instances (symbols: RelationshipSchemaAPI, ancestors, descendants) and add kind=RelationshipKind.HIERARCHY to those two entries; leave other properties (cardinality, read_only, optional) unchanged and ensure no behavior relies on the default kind in _process_hierarchical_fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@infrahub_sdk/schema/main.py`:
- Around line 370-383: The ancestors and descendants RelationshipSchemaAPI
entries currently omit kind, defaulting to GENERIC; update them to explicitly
set kind=RelationshipKind.HIERARCHY for semantic consistency with parent and
children. Locate the list returning RelationshipSchemaAPI instances (symbols:
RelationshipSchemaAPI, ancestors, descendants) and add
kind=RelationshipKind.HIERARCHY to those two entries; leave other properties
(cardinality, read_only, optional) unchanged and ensure no behavior relies on
the default kind in _process_hierarchical_fields.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ba4bb2ba-54ac-4a98-a960-852de8d0a005
📒 Files selected for processing (2)
infrahub_sdk/node/node.pyinfrahub_sdk/schema/main.py
Why
The node initialization code in InfrahubNodeBase was determining capability flags (_artifact_support, _file_object_support, _hierarchy_support, _artifact_definition_support) by inspecting schema internals directly — using getattr to reach into inherit_from, string comparisons against hardcoded kind names, and isinstance checks to exclude schema types that don't carry certain fields. This logic belonged on the schema layer, not the node layer.
The change moves these capability checks to where the relevant data lives: BaseSchema provides safe defaults (False / []) for all schema types, and NodeSchemaAPI overrides them with real logic using its own fields (inherit_from, hierarchy). The same pattern is applied to hierarchical_relationship_schemas — rather than constructing four hardcoded RelationshipSchemaAPI objects inline in _init_relationships (duplicated across the async and sync classes), the schema itself now produces the correct pseudo-schemas for hierarchical nodes.
The result is that node.py no longer needs to know anything about the structure of the schema to determine what a node supports. Four uniform assignments replace a mix of getattr hacks, isinstance guards, and inline schema construction. The _init_relationships hierarchical block drops from ~70 lines (×2 for async/sync) to a single loop.
What changed
Summary by CodeRabbit
New Features
Improvements