fix(node): clarify upsert guard message for pool-sourced HFID attributes#1106
Merged
Conversation
The ValidationError raised by _validate_upsert claimed the upsert "cannot resolve the HFID without a concrete value", implying a backend crash. Since #312 the SDK no longer sends the HFID in the upsert payload, so that premise is stale. The real problem is different: a CoreNumberPool assigns a new value on every creation, so a pool-sourced HFID attribute is never stable, an upsert can never match an existing node by it, and every run would silently create a duplicate. Reword the error message and docstring to describe this, and point to the idempotent alternatives (look the node up by a stable field and reuse it, or set an explicit id). Update the resource manager guide to match and replace the misleading "two-step pattern" with the lookup-and-reuse pattern that the demo generators actually use. Add an integration test characterising the real backend behaviour (a no-id upsert creates and allocates the pool value; a re-run duplicates) and extend the unit test to cover the new message. Refs #339, #396
Deploying infrahub-sdk-python with
|
| Latest commit: |
853e01d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://dbcf25f8.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://fix-numberpool-hfid-upsert-m.infrahub-sdk-python.pages.dev |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## stable #1106 +/- ##
=======================================
Coverage 82.15% 82.16%
=======================================
Files 138 138
Lines 11896 11896
Branches 1784 1784
=======================================
+ Hits 9773 9774 +1
+ Misses 1575 1572 -3
- Partials 548 550 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
minitriga
approved these changes
Jun 26, 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.
The ValidationError raised by _validate_upsert claimed the upsert "cannot resolve the HFID without a concrete value", implying a backend crash. Since #312 the SDK no longer sends the HFID in the upsert payload, so that premise is stale. The real problem is different: a CoreNumberPool assigns a new value on every creation, so a pool-sourced HFID attribute is never stable, an upsert can never match an existing node by it, and every run would silently create a duplicate.
Reword the error message and docstring to describe this, and point to the idempotent alternatives (look the node up by a stable field and reuse it, or set an explicit id). Update the resource manager guide to match and replace the misleading "two-step pattern" with the lookup-and-reuse pattern that the demo generators actually use.
Add an integration test characterising the real backend behaviour (a no-id upsert creates and allocates the pool value; a re-run duplicates) and extend the unit test to cover the new message.
Refs #339, #396
Why
The client-side guard added in #1014 (
InfrahubNode._validate_upsert) raises aValidationErrorwhen you callsave(allow_upsert=True)on a node whose human-friendly identifier (HFID) includes aCoreNumberPool-sourced attribute. Its message says the upsert "cannot resolve the HFID without a concrete value", which implies a backend/HFID-resolution failure. That premise is stale: since #312 the SDK no longer sends the HFID in the upsert payload, so there is no such crash.This surfaced while reviewing opsmill/infrahub-demo-service-catalog#114, where the VLAN generator hit this guard. The real reason the operation is a problem is different and worth stating correctly: a
CoreNumberPoolallocates a new value on every creation, so a pool-sourced HFID attribute is never stable. An upsert can therefore never match an existing node and would silently create a duplicate on each run.Goal: make the error message and docs explain the actual problem and point to the patterns that work.
Non-goals: this does NOT change the guard's behavior (it still blocks, which is correct - the alternative is silent duplicate creation) and does NOT add idempotent number-pool allocation (that's #396).
What changed
Behavioral changes:
Message/docs:
ValidationErrormessage and_validate_upsertdocstring to describe the non-idempotency/silent-duplication problem and the fix: look the node up by a stable attribute or relationship and reuse it, or set an explicitid.Tests:
What stayed the same: guard logic, public API, and when the error fires are all unchanged.
Summary by cubic
Clarified the upsert guard for nodes whose HFID includes a
CoreNumberPoolvalue: pool values change on each creation, so the HFID is unstable and upserts would duplicate; the SDK now raises a clearer error with guidance. Updated docs to promote the lookup-and-reuse pattern and added tests to characterize backend behavior.ValidationErrorand docstring inInfrahubNode._validate_upsertto explain non-idempotent duplicates and suggest alternatives (lookup by a stable field/relationship or set an explicitidbeforesave(allow_upsert=True)).CoreNumberPoolHFID limitation.Written for commit 853e01d. Summary will update on new commits.