Skip to content

IHS-119: Fix upsert not working for numberpool and attribute in hfid#1014

Open
solababs wants to merge 5 commits into
stablefrom
sb-12052026-fix-upsert-numberpool-hfid-ihs-119
Open

IHS-119: Fix upsert not working for numberpool and attribute in hfid#1014
solababs wants to merge 5 commits into
stablefrom
sb-12052026-fix-upsert-numberpool-hfid-ihs-119

Conversation

@solababs
Copy link
Copy Markdown
Contributor

@solababs solababs commented May 12, 2026

Why

node.save(allow_upsert=True) on a node whose human-friendly identifier (HFID) contains a CoreNumberPool-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 ValidationError before any network call is made.

Closes #339

How to test

cd python_sdk

# All four upsert guard tests
uv run pytest tests/unit/sdk/pool/test_attribute_from_pool.py -v -k "upsert"

Checklist

  • Tests added/updated
  • Changelog entry added (python_sdk/changelog/339.fixed.md)
  • External docs updated (docs/docs/python-sdk/guides/resource-manager.mdx)
  • Internal .md docs updated (internal knowledge and AI code tools knowledge)

Summary by cubic

Adds a client-side guard to stop crashes when calling save(allow_upsert=True) on nodes whose HFID includes a CoreNumberPool-sourced attribute; it now raises a clear ValidationError before any request. Addresses IHS-119.

  • Bug Fixes
    • Added a guard in async and sync InfrahubNode.save() to block upsert when an HFID component is an unresolved pool-backed attribute (either a from_pool dict with no value or a pool node object); raises ValidationError early.
    • Upsert still works when an id is set or when the pool-backed attribute is not part of the HFID.
    • Added 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

@solababs solababs requested a review from a team as a code owner May 12, 2026 10:12
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 12, 2026

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

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

View logs

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 45.45455% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/node/node.py 36.84% 10 Missing and 2 partials ⚠️

❗ There is a different number of reports uploaded between BASE (c300a41) and HEAD (da072d3). Click for more details.

HEAD has 8 uploads less than BASE
Flag BASE (c300a41) HEAD (da072d3)
python-3.12 2 1
python-3.10 2 1
python-3.11 2 1
python-filler-3.12 2 1
python-3.14 2 1
python-3.13 2 1
integration-tests 2 0
@@            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     
Flag Coverage Δ
integration-tests ?
python-3.10 54.61% <36.36%> (+0.02%) ⬆️
python-3.11 54.59% <36.36%> (+<0.01%) ⬆️
python-3.12 54.59% <36.36%> (+0.02%) ⬆️
python-3.13 54.59% <36.36%> (+<0.01%) ⬆️
python-3.14 54.61% <36.36%> (+0.02%) ⬆️
python-filler-3.12 22.63% <9.09%> (-0.08%) ⬇️

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

Files with missing lines Coverage Δ
infrahub_sdk/node/attribute.py 100.00% <100.00%> (ø)
infrahub_sdk/node/node.py 79.64% <36.84%> (-7.25%) ⬇️

... and 39 files with indirect coverage changes

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

Comment thread infrahub_sdk/node/node.py Outdated
attr = self._get_attribute(attr_name)
except ResourceNotDefinedError:
continue
if attr.is_from_pool_attribute():
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.

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?

@solababs solababs requested a review from ogenstad May 26, 2026 10:14
Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

1 issue found across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread infrahub_sdk/node/node.py Outdated
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.

bug: Upsert not working for nodes that are assigning an attribute via a NumberPool and attribute in HFID

2 participants