Skip to content

Make RelatedNode/RelationshipManager generic over peer type (#1063)#1065

Merged
FragmentedPacket merged 11 commits into
developfrom
ihs-relatednode-generic-1063
Jun 8, 2026
Merged

Make RelatedNode/RelationshipManager generic over peer type (#1063)#1065
FragmentedPacket merged 11 commits into
developfrom
ihs-relatednode-generic-1063

Conversation

@FragmentedPacket

@FragmentedPacket FragmentedPacket commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #1063. Stacked on top of #763 (base branch is #763's re-sb-20260119-fix-typing-for-protocols-ihs-183); retarget to develop once #763 merges.

Problem

RelatedNode.peer / RelationshipManager are typed against the dynamic InfrahubNode, so traversing a relationship loses the peer's type. Any chain through .peer / .peers collapses to the catch-all Attribute | RelationshipManager | RelatedNode union and fails under mypy/ty with union-attr. This became visible to downstream consumers when py.typed was added in 1.19.0.

Change

  • RelatedNode, RelatedNodeSync, RelationshipManager, RelationshipManagerSync are now generic over the peer type (PeerT / PeerTSync), defaulting to InfrahubNode / InfrahubNodeSync (PEP 696) so all existing un-parameterised usage is unchanged.
  • infrahubctl protocols parameterises 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

  • SDK: mypy (125 files) ✅, ty ✅, ruff ✅, generator test updated, 252 node/relationship/store unit tests ✅.
  • Against a downstream repo (the AI/DC solution) on the released line: relationship traversal union-attr errors went from 52 → 0. (Remaining downstream errors are a separate relationship-assignment issue, bug: assigning to a relationship attribute fails mypy (assignment) for id strings and nodes #1064, plus genuinely-unsound accesses now correctly surfaced, e.g. accessing NetworkInterface-only attributes on a generic NetworkEndpoint peer.)

Notes

  • The bundled infrahub_sdk/protocols.py is left as-is (bare relationships still resolve via the InfrahubNode default); it can be regenerated with the new generator separately.

🤖 Generated with Claude Code


Summary by cubic

Make RelatedNode/RelatedNodeSync and RelationshipManager/RelationshipManagerSync generic over their peer type so .peer, .peers, and indexing return the concrete peer; regenerate SDK docs to show PeerT/PeerTSync returns, fixing #1063. Defaults keep existing code working by falling back to InfrahubNode/InfrahubNodeSync.

  • New Features
    • Peer type defaults (PEP 696) to InfrahubNode/InfrahubNodeSync for backward compatibility.
    • infrahubctl protocols outputs RelatedNode[Peer] and RelationshipManager[Peer]; sync output uses PeerSync when available.
    • Hierarchical fields are typed: parent: RelatedNode[Self], children: RelationshipManager[Self].

Written for commit da2e3f3. Summary will update on new commits.

Review in cubic

solababs and others added 9 commits January 22, 2026 10:50
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

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/node/related_node.py 87.50% 2 Missing ⚠️
@@             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     
Flag Coverage Δ
integration-tests 41.61% <21.21%> (-0.93%) ⬇️
python-3.10 55.26% <42.42%> (-0.74%) ⬇️
python-3.11 55.24% <42.42%> (-0.77%) ⬇️
python-3.12 55.24% <42.42%> (-0.76%) ⬇️
python-3.13 55.24% <42.42%> (-0.76%) ⬇️
python-3.14 55.25% <42.42%> (-0.74%) ⬇️
python-filler-3.12 22.36% <51.51%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/node/relationship.py 81.86% <100.00%> (ø)
infrahub_sdk/protocols_generator/generator.py 95.12% <100.00%> (+0.12%) ⬆️
infrahub_sdk/node/related_node.py 92.57% <87.50%> (+0.12%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Re-trigger cubic

@ogenstad ogenstad force-pushed the re-sb-20260119-fix-typing-for-protocols-ihs-183 branch from 6c5bd98 to 99ce971 Compare June 8, 2026 07:00
@ogenstad ogenstad requested a review from a team as a code owner June 8, 2026 07:00

@ajtmccarty ajtmccarty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 8, 2026

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

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

View logs

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>
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label Jun 8, 2026
@FragmentedPacket FragmentedPacket merged commit b47bb9c into develop Jun 8, 2026
21 checks passed
@FragmentedPacket FragmentedPacket deleted the ihs-relatednode-generic-1063 branch June 8, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants