feat(protocols): regenerate protocols with peer-typed relationships [IFC-3054] - #1285
Open
ogenstad wants to merge 2 commits into
Open
feat(protocols): regenerate protocols with peer-typed relationships [IFC-3054]#1285ogenstad wants to merge 2 commits into
ogenstad wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## infrahub-develop #1285 +/- ##
====================================================
+ Coverage 84.46% 85.33% +0.87%
====================================================
Files 147 148 +1
Lines 13296 14085 +789
Branches 1930 1936 +6
====================================================
+ Hits 11230 12020 +790
+ Misses 1503 1499 -4
- Partials 563 566 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
ogenstad
force-pushed
the
pog-sdk-core-protocols-artifact-IFC-3054
branch
from
August 27, 2026 07:55
ab2d4ad to
75a0631
Compare
Deploying infrahub-sdk-python with
|
| Latest commit: |
fe31f2a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6e332eeb.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://pog-sdk-core-protocols-artif.infrahub-sdk-python.pages.dev |
ogenstad
force-pushed
the
pog-sdk-core-protocols-artifact-IFC-3054
branch
from
August 27, 2026 10:04
75a0631 to
ba1fffd
Compare
The models were sorted on the schema name without its namespace, so BuiltinIPPrefix sorted under IPPrefix, and two kinds sharing a name were left in whatever order the caller supplied them. The rendered module is committed and validated by regenerating it and diffing, so an ordering that depends on the input order can turn into a build that fails intermittently once such a pair exists. Sort on the kind instead, which is the name each class renders as. Case is ignored so the file still reads alphabetically, with the kind itself breaking ties, since a case-insensitive key on its own would compare InfraDevice and INfraDEvice equal and reintroduce the same problem. This also keeps the order the protocols module shipped with before it moved to this generator.
…IFC-3054] Regenerated by "invoke backend.generate", which now renders this module through the SDK's own code generator instead of a separate template kept in the Infrahub repository. That template had drifted: it emitted bare RelatedNode and RelationshipManager, dropping the peer type of every relationship. Every relationship now carries its peer, cardinality-one relationships use the assignable RelationshipAttribute descriptor, and the module gains the relationships the API exposes implicitly along with four Profile kinds it was missing. Attributes follow their schema kind and are no longer optional when they always hold a value. CoreGenericAccount.tokens and .external_identities are gone. Their peers are internal, so /api/schema never exposed them and nothing consumes them. The golden fixtures move because the four Profile kinds are now importable from this module, so protocols generated for a user schema import them instead of redefining them.
ogenstad
force-pushed
the
pog-sdk-core-protocols-artifact-IFC-3054
branch
from
August 27, 2026 10:56
ba1fffd to
fe31f2a
Compare
ogenstad
marked this pull request as ready for review
August 27, 2026 13:13
ajtmccarty
approved these changes
Aug 27, 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.
Why
Follow-up to #1273, which taught the generator to render this module but deliberately did not
regenerate it. This is the regenerated artifact.
Until now
infrahub_sdk/protocols.pycame from a second Jinja template kept in the Infrahubrepository, which had drifted from the generator behind
infrahubctl protocols: it emitted bareRelatedNodeandRelationshipManager, so the protocols we ship lost the peer type of everyrelationship.
invoke backend.generatein Infrahub now feeds the processed core schema through thegenerator from #1273, so this module and the protocols a user generates for their own schema come
from one renderer and cannot drift apart again.
It also carries a one-line generator fix, because the two are entangled: the sort key decides the
artifact's ordering, so landing them separately would mean regenerating this file twice and
resolving a conflict on the golden fixtures for no gain.
Non-goals: no other hand-written code changes.
Part of IFC-3054. Needs the matching Infrahub change, which is not merged yet, so do not regenerate
from Infrahub
developuntil that lands.What changed
Ordering fix (
generator.py, one line)Models were sorted on the schema name without its namespace, so
BuiltinIPPrefixsorted underIPPrefix. That key is also not unique: a kind is its namespace plus its name, so two kinds sharinga name tie, and the tie fell to whatever order the schema was supplied in. This file is committed
and validated by regenerating it and diffing, so once such a pair exists that becomes a build
failing intermittently with unchanged inputs. There is no such pair in the core schema today, which
is why it is worth fixing before someone hits it.
Sorting on
(kind.lower(), kind)makes the ordering total.kindis the name each class rendersas, and every schema type the generator accepts exposes it. Case is ignored so the file still reads
alphabetically, with the kind itself breaking ties, because a case-insensitive key on its own
compares
InfraDeviceandINfraDEviceequal and reintroduces the same problem. As a side effectthis keeps this module's existing class order, so the artifact diff below is content only.
For users: regenerating with
infrahubctl protocolsreorders the classes in their file and changesnothing else.
Regenerated protocols
node.rel.peerandnode.many_rel.peers[0].peerresolve to the peer's protocol instead of a bare
InfrahubNode.RelationshipAttributedescriptor, so they can be assignedan id, an HFID, a peer node or
Noneand still read back as a typedRelatedNode. Previouslyassigning an id was a type error, despite being what the runtime supports.
member_of_groups,subscriber_of_groups,profiles.ProfileBuiltinIPAddress,ProfileBuiltinIPPrefix,ProfileBuiltinTagand
ProfileIpamNamespacekinds in both variants.kind.
CoreGlobalPermission.decisionandCoreObjectPermission.decisionbecomeIntegerratherthan
Enum, which is the type the API actually returns.CoreGenericAccount.tokensand.external_identitiesare gone. Their peers are internal, so/api/schemanever exposed them: the module was advertising two relationships the API does nothave. Nothing in this repository or in Infrahub consumes them.
Profile*kinds above instead ofredefining them, which is part of why the golden fixtures move. That import is at runtime, so
from schema_protocols import ProfileBuiltinTagkeeps working.What stayed the same
parsing both versions and diffing the class and member sets.
commitonCoreGenericRepository, added in chore(schema): add commit to the CoreGenericRepository protocol [IFC-2954] #1272, is retained. It moves within its class only,because attributes are sorted by name.
still inherit, so this is verbosity rather than a change in meaning.
How to review
Suggested order:
infrahub_sdk/protocols_generator/generator.py, one line, plustest_render_order_does_not_depend_on_input_order. It covers the two ways a weaker key can tie,two kinds sharing a name and two names differing only in case, and asserts that supplying the
schema in either order renders identically.
you know well.
CoreGenericRepositoryis a good one, gaining peer types,credentialbecomingRelationshipAttribute[CoreCredential], andmember_of_groupsandsubscriber_of_groupsappearing.
Profile*classes becoming imports, and the reordering.Regenerating is the real check on the artifact, but it needs the Infrahub side, so it cannot be done
from this repository alone.
How to test
ruff, ty and mypy are clean over the regenerated module, which is what mattered most here given it
is now about 2,200 lines with descriptor annotations.
From an Infrahub checkout with the matching branch,
uv run invoke backend.validate-generatedexits 0, and generating twice produces an identical file. Rendering in six separate processes with
four fixed
PYTHONHASHSEEDvalues plus two random ones also produces an identical SHA-256.Impact & rollout
decisionfields changing fromstrtoint. Both are listed above and in the changelog.bumps the submodule pointer to include this commit.
Checklist