Repository navigation
fix(infrahub): fetch a stored peer again when it lacks a required relationship - #462
Draft
pcDamasceno wants to merge 1 commit into
Draft
pcDamasceno wants to merge 1 commit into
pcDamasceno wants to merge 1 commit into
Conversation
…ationship Fixes #461. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deploying infrahub-sync with
|
| Latest commit: |
3c3f892
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fb333612.infrahub-sync.pages.dev |
| Branch Preview URL: | https://fix-peer-missing-required-re.infrahub-sync.pages.dev |
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 #461.
Bug
Loading the Infrahub side of a diff or sync failed with
Cannot build unique_id for peer LocationRack[...] (relationship DcimDevice.location ...): missing identifier key(s) ['site'], although the mapping declaressiteand the rack has its site in Infrahub.--continue-on-erroronly skipped the relationship, so devices lost their location.model_loaderloads a kind withclient.all(..., include=..., populate_store=True). Whenincludenames a relationship, the SDK also builds a node for each peer and stores it.DcimDevice.locationpoints to the genericLocationHosting, so that node carries only what the generic declares, withoutsite, and it replaces the rack loaded earlier in the store.resolve_peer_nodefetched a stored peer again only when a required attribute was empty, so the partial rack was used.Circumstances
A peer whose identifiers include a relationship that a generic does not declare, reached through that generic by a kind loaded after it. Here
LocationRack(identifierssite,name) throughDcimDevice.location.How it was caught
Syncing NetBox racks and devices into Infrahub 1.12.5 with the dcim schemas and the rack extension of the schema library.
Fix
The completeness check in
resolve_peer_node(renamed_node_is_complete) also treats a stored peer as incomplete when a required cardinality-one relationship holds no id, so the peer is fetched again by its concrete kind. Before,resolve_peer_nodereturned the partial rack withsite.id == None. After, it returns the rack with its site. The cost is one fetch per such peer each time a kind that points to it is loaded.Two tests cover a stored peer with and without its required relationship. The fake relationship schema in
test_infrahub_node_to_diffsync.pygains theoptionalfield that real relationship schemas carry.No user-visible changes: no CLI flag or config key changes.
Not covered
Test plan
pytest tests/adapters: 226 passed, 3 skipped.ruff format,ruff checkandty checkclean on the changed files.resolve_peer_nodenow returns the rack with its site.rumdlhook was skipped for the commit only because it lints the whole working tree, including an untracked local folder. An export of the committed tree passesrumdlwith no issues.🤖 Generated with Claude Code