Skip to content

Conversation

@minitriga
Copy link
Contributor

@minitriga minitriga commented Feb 9, 2026

When saving a hierarchical node with allow_upsert=True, the SDK was including parent: null in the GraphQL mutation for nodes without a parent (e.g. top-level fabric nodes). Infrahub rejects this because hierarchy relationships are not assignable via mutations.

Skip hierarchy relationships in _generate_input_data() unless they were explicitly initialized with data.

Summary by CodeRabbit

  • Bug Fixes

    • Mutation payloads now omit uninitialized hierarchical relationships (parent/children/ancestors/descendants) unless explicitly set, preventing unintended data from being sent.
  • Tests

    • Added tests verifying hierarchical relationship input data is excluded when uninitialized and included when explicitly initialized, across both standard and sync client modes.

@minitriga minitriga requested a review from a team as a code owner February 9, 2026 11:52
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

Walkthrough

Adds a guard in input-data generation to skip hierarchical relationships (parent, children, ancestors, descendants) unless those relationships have been explicitly initialized, preventing uninitialized hierarchical relations from being included in mutation payloads. The change is confined to the relationship-processing loop in node input generation. Tests were added to verify that uninitialized hierarchical relations are excluded and explicitly initialized ones are included, covering both standard and sync client paths.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: preventing uninitialized hierarchy relationships from being included in mutation payloads, which directly addresses the problem statement.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

When saving a hierarchical node with allow_upsert=True, the SDK was
including `parent: null` in the GraphQL mutation for nodes without a
parent (e.g. top-level fabric nodes). Infrahub rejects this because
hierarchy relationships are not assignable via mutations.

Skip hierarchy relationships in _generate_input_data() unless they
were explicitly initialized with data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@minitriga minitriga force-pushed the fix/skip-hierarchy-relationships-in-upsert-stable branch from ef3aab1 to 40eb72c Compare February 9, 2026 11:58
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 9, 2026

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 40eb72c
Status: ✅  Deploy successful!
Preview URL: https://52c4f66e.infrahub-sdk-python.pages.dev
Branch Preview URL: https://fix-skip-hierarchy-relations-y0nh.infrahub-sdk-python.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/unit/sdk/test_hierarchical_nodes.py`:
- Around line 50-54: Replace the tuple membership test with a set literal to
satisfy PLR6201: in the loop over schema_api.relationships where you check
rel.name in ("parent", "children"), change that membership test to use a set
literal {"parent", "children"} so the condition uses a set for faster membership
checks (refer to the loop and the rel.name check).

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##           stable     #810      +/-   ##
==========================================
- Coverage   80.37%   80.34%   -0.03%     
==========================================
  Files         115      115              
  Lines        9873     9875       +2     
  Branches     1504     1505       +1     
==========================================
- Hits         7935     7934       -1     
- Misses       1416     1420       +4     
+ Partials      522      521       -1     
Flag Coverage Δ
integration-tests 41.42% <100.00%> (-0.02%) ⬇️
python-3.10 51.39% <100.00%> (+<0.01%) ⬆️
python-3.11 51.39% <100.00%> (+<0.01%) ⬆️
python-3.12 51.41% <100.00%> (+<0.01%) ⬆️
python-3.13 51.41% <100.00%> (+0.03%) ⬆️
python-3.14 53.03% <100.00%> (+<0.01%) ⬆️
python-filler-3.12 24.06% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
infrahub_sdk/node/node.py 85.05% <100.00%> (-0.29%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@ajtmccarty ajtmccarty left a comment

Choose a reason for hiding this comment

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

I am not the most familiar with all the inner workings of the SDK, but I think this looks reasonable
I'd give it a day for anyone else on @opsmill/backend to review before merging

@minitriga
Copy link
Contributor Author

Closing this and creating a better issue to track this as there is a larger problem here: #821

@minitriga minitriga closed this Feb 11, 2026
@minitriga minitriga deleted the fix/skip-hierarchy-relationships-in-upsert-stable branch February 11, 2026 14:16
@minitriga minitriga restored the fix/skip-hierarchy-relationships-in-upsert-stable branch February 11, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants