Make RelatedNode/RelationshipManager generic over peer type (#1063)#1065
Merged
Conversation
Parameterise RelatedNode, RelatedNodeSync, RelationshipManager and RelationshipManagerSync over the peer type (defaulting to InfrahubNode/ InfrahubNodeSync for backward compatibility) and have infrahubctl protocols emit the peer type for each relationship. Relationship traversal via .peer/ .peers/indexing now preserves the peer type instead of collapsing to the dynamic InfrahubNode. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## develop #1065 +/- ##
===========================================
- Coverage 82.26% 81.83% -0.43%
===========================================
Files 135 135
Lines 11951 11670 -281
Branches 1784 1762 -22
===========================================
- Hits 9831 9550 -281
- Misses 1573 1575 +2
+ Partials 547 545 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
6c5bd98 to
99ce971
Compare
ajtmccarty
reviewed
Jun 8, 2026
ajtmccarty
left a comment
Contributor
There was a problem hiding this comment.
looks like a big typing improvement, but there are conflicts
Base automatically changed from
re-sb-20260119-fix-typing-for-protocols-ihs-183
to
develop
June 8, 2026 19:04
…neric-1063 # Conflicts: # .pre-commit-config.yaml # infrahub_sdk/node/related_node.py # infrahub_sdk/node/relationship.py # infrahub_sdk/protocols_base.py
Deploying infrahub-sdk-python with
|
| Latest commit: |
da2e3f3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://bc9a4983.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://ihs-relatednode-generic-1063.infrahub-sdk-python.pages.dev |
The develop merge combined upstream peer/get docstrings with our generic PeerT/PeerTSync return types, leaving the committed related_node.mdx stale. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ajtmccarty
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1063. Stacked on top of #763 (base branch is #763's
re-sb-20260119-fix-typing-for-protocols-ihs-183); retarget todeveloponce #763 merges.Problem
RelatedNode.peer/RelationshipManagerare typed against the dynamicInfrahubNode, so traversing a relationship loses the peer's type. Any chain through.peer/.peerscollapses to the catch-allAttribute | RelationshipManager | RelatedNodeunion and fails under mypy/ty withunion-attr. This became visible to downstream consumers whenpy.typedwas added in 1.19.0.Change
RelatedNode,RelatedNodeSync,RelationshipManager,RelationshipManagerSyncare now generic over the peer type (PeerT/PeerTSync), defaulting toInfrahubNode/InfrahubNodeSync(PEP 696) so all existing un-parameterised usage is unchanged.infrahubctl protocolsparameterises each relationship:device: RelatedNode[NetworkDevice],interfaces: RelationshipManager[NetworkInterface], etc. Core peers are syncified in sync output (tags: RelationshipManagerSync[BuiltinTagSync]); locally generated classes keep their name.Generic[...]is a typing-only change — zero runtime cost.Verification
mypy(125 files) ✅,ty✅,ruff✅, generator test updated, 252 node/relationship/store unit tests ✅.union-attrerrors went from 52 → 0. (Remaining downstream errors are a separate relationship-assignmentissue, bug: assigning to a relationship attribute fails mypy (assignment) for id strings and nodes #1064, plus genuinely-unsound accesses now correctly surfaced, e.g. accessingNetworkInterface-only attributes on a genericNetworkEndpointpeer.)Notes
infrahub_sdk/protocols.pyis left as-is (bare relationships still resolve via theInfrahubNodedefault); it can be regenerated with the new generator separately.🤖 Generated with Claude Code
Summary by cubic
Make
RelatedNode/RelatedNodeSyncandRelationshipManager/RelationshipManagerSyncgeneric over their peer type so.peer,.peers, and indexing return the concrete peer; regenerate SDK docs to showPeerT/PeerTSyncreturns, fixing #1063. Defaults keep existing code working by falling back toInfrahubNode/InfrahubNodeSync.InfrahubNode/InfrahubNodeSyncfor backward compatibility.infrahubctl protocolsoutputsRelatedNode[Peer]andRelationshipManager[Peer]; sync output usesPeerSyncwhen available.parent: RelatedNode[Self],children: RelationshipManager[Self].Written for commit da2e3f3. Summary will update on new commits.