IHS-119: Fix upsert not working for numberpool and attribute in hfid#1014
IHS-119: Fix upsert not working for numberpool and attribute in hfid#1014solababs wants to merge 5 commits into
Conversation
Deploying infrahub-sdk-python with
|
| Latest commit: |
da072d3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://41292ab9.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://sb-12052026-fix-upsert-numbe.infrahub-sdk-python.pages.dev |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## stable #1014 +/- ##
==========================================
- Coverage 81.56% 74.41% -7.16%
==========================================
Files 134 134
Lines 11442 11490 +48
Branches 1730 1742 +12
==========================================
- Hits 9333 8550 -783
- Misses 1564 2398 +834
+ Partials 545 542 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 39 files with indirect coverage changes 🚀 New features to boost your workflow:
|
| attr = self._get_attribute(attr_name) | ||
| except ResourceNotDefinedError: | ||
| continue | ||
| if attr.is_from_pool_attribute(): |
There was a problem hiding this comment.
I'm wondering if we should forbid this all together if the attribute can come from a pool. It could be that we should have
if attr.value is not None and attr.is_from_pool_attribute():I.e. that this would be problematic for upsert mutations if a value hadn't been assigned from a pool already. Was that something that you considered?
There was a problem hiding this comment.
1 issue found across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Why
node.save(allow_upsert=True)on a node whose human-friendly identifier (HFID) contains aCoreNumberPool-sourced attribute crashes with"invalid literal for int() with base 10: 'VLAN ID Pool - Test'". The backend upsert resolver tries to use the unresolved pool reference as an HFID component, but the integer value is not assigned until after the server creates the node — making the upsert semantically impossible.This PR adds a client-side guard that detects the pattern and raises a descriptive
ValidationErrorbefore any network call is made.Closes #339
How to test
Checklist
python_sdk/changelog/339.fixed.md)docs/docs/python-sdk/guides/resource-manager.mdx)Summary by cubic
Adds a client-side guard to stop crashes when calling
save(allow_upsert=True)on nodes whose HFID includes aCoreNumberPool-sourced attribute; it now raises a clearValidationErrorbefore any request. Addresses IHS-119.InfrahubNode.save()to block upsert when an HFID component is an unresolved pool-backed attribute (either afrom_pooldict with no value or a pool node object); raisesValidationErrorearly.idis set or when the pool-backed attribute is not part of the HFID.is_unresolved_pool_attribute()for attributes; expanded tests; updated the Resource Manager guide with warning and alternatives and the SDK reference; added a changelog entry.Written for commit da072d3. Summary will update on new commits. Review in cubic