Skip to content

Conversation

@minitriga
Copy link
Contributor

@minitriga minitriga commented Dec 23, 2025

…pplying (#634)

  • Initial plan

  • Fix optional attributes not being set when using object templates

  • Modified _generate_input_data() to skip adding None for optional relationships on new nodes
  • For existing nodes, still include None to allow clearing relationships (preserves PR IHS-152 Allow unsetting one-to-one relationship #515 behavior)
  • Updated tests to reflect new behavior
  • Added test to verify existing nodes still work correctly
  • Add type annotations to test parameters and use BothClients fixture
  • Added BothClients import to TYPE_CHECKING block
  • Updated test_update_input_data_existing_node_with_optional_relationship to use clients fixture with proper type annotations
  • Changed from client fixture to clients fixture (clients.standard and clients.sync)
  • Added type annotation for client_type parameter
  • Use future annotations and add changelog for issue 630
  • Added from __future__ import annotations to enable postponed evaluation
  • Changed clients: "BothClients" to clients: BothClients without string quotes
  • Moved GenericSchema, NodeSchemaAPI, and HTTPXMock imports to TYPE_CHECKING block
  • Added changelog/630.fixed.md documenting the fix
  • Fix linting: correct import path in TYPE_CHECKING block

Changed from tests.unit.sdk.conftest import BothClients to from .conftest import BothClients to fix ruff import sorting error after merge from stable branch.


Summary by CodeRabbit

  • Bug Fixes
    • Fixed SDK handling of uninitialized optional relationships when creating nodes with object templates to enable the backend to properly apply template defaults. New nodes now correctly leverage defaults while existing nodes preserve the ability to clear and update relationships. This improves the initialization process and data consistency for templated nodes.

✏️ Tip: You can customize this high-level summary in your review settings.

…pplying (#634)

* Initial plan

* Fix optional attributes not being set when using object templates

- Modified _generate_input_data() to skip adding None for optional relationships on new nodes
- For existing nodes, still include None to allow clearing relationships (preserves PR #515 behavior)
- Updated tests to reflect new behavior
- Added test to verify existing nodes still work correctly

Co-authored-by: minitriga <[email protected]>

* Add type annotations to test parameters and use BothClients fixture

- Added BothClients import to TYPE_CHECKING block
- Updated test_update_input_data_existing_node_with_optional_relationship to use clients fixture with proper type annotations
- Changed from client fixture to clients fixture (clients.standard and clients.sync)
- Added type annotation for client_type parameter

Co-authored-by: minitriga <[email protected]>

* Use __future__ annotations and add changelog for issue 630

- Added `from __future__ import annotations` to enable postponed evaluation
- Changed `clients: "BothClients"` to `clients: BothClients` without string quotes
- Moved GenericSchema, NodeSchemaAPI, and HTTPXMock imports to TYPE_CHECKING block
- Added changelog/630.fixed.md documenting the fix

Co-authored-by: minitriga <[email protected]>

* Fix linting: correct import path in TYPE_CHECKING block

Changed `from tests.unit.sdk.conftest import BothClients` to `from .conftest import BothClients` to fix ruff import sorting error after merge from stable branch.

Co-authored-by: minitriga <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: minitriga <[email protected]>
Co-authored-by: Alex Gittings <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Dec 23, 2025

Walkthrough

The pull request includes a changelog entry documenting a SDK fix for handling uninitialized optional relationships. The _generate_input_data method signature is updated with an optional request_context parameter. The behavior for uninitialized optional relationships is modified: when creating new nodes, these fields are now omitted to allow object template defaults to apply; for existing nodes, they remain set to None to preserve relationship-clearing behavior. Tests are added and updated to verify this new behavior.

Pre-merge checks

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title is truncated and incomplete ('Fix optional relationships preventing object template defaults from a…'), making it impossible to fully evaluate if it accurately summarizes the main change. Provide the complete pull request title to assess whether it fully captures the main change of handling optional relationships differently for new versus existing nodes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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.

@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/node/node.py 75.00% 0 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##           stable     #710      +/-   ##
==========================================
+ Coverage   75.48%   76.03%   +0.55%     
==========================================
  Files         113      113              
  Lines        9512     9744     +232     
  Branches     1893     1491     -402     
==========================================
+ Hits         7180     7409     +229     
- Misses       1832     1840       +8     
+ Partials      500      495       -5     
Flag Coverage Δ
integration-tests 34.64% <50.00%> (-0.26%) ⬇️
python-3.10 49.95% <75.00%> (+1.16%) ⬆️
python-3.11 49.95% <75.00%> (+1.16%) ⬆️
python-3.12 49.93% <75.00%> (+1.18%) ⬆️
python-3.13 49.93% <75.00%> (+1.16%) ⬆️
python-3.14 51.57% <75.00%> (?)
python-3.9 ?
python-filler-3.12 23.94% <0.00%> (-0.36%) ⬇️

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 79.19% <75.00%> (+2.45%) ⬆️

... and 26 files with indirect coverage changes

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

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: 0

🧹 Nitpick comments (1)
tests/unit/sdk/test_node.py (1)

22-28: Duplicate import: HTTPXMock is already imported at runtime.

HTTPXMock is imported at line 8 (from pytest_httpx import HTTPXMock) and again inside the TYPE_CHECKING block at line 23. Since it's needed at runtime for the test function signatures, the TYPE_CHECKING import is redundant.

🔎 Suggested fix
 if TYPE_CHECKING:
-    from pytest_httpx import HTTPXMock
-
     from infrahub_sdk.client import InfrahubClient, InfrahubClientSync
     from infrahub_sdk.schema import GenericSchema, NodeSchemaAPI

     from .conftest import BothClients
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f1cb0c and 379d288.

📒 Files selected for processing (3)
  • changelog/630.fixed.md
  • infrahub_sdk/node/node.py
  • tests/unit/sdk/test_node.py
🧰 Additional context used
📓 Path-based instructions (5)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use type hints on all function signatures
Never mix async/sync inappropriately
Never bypass type checking without justification

Files:

  • tests/unit/sdk/test_node.py
  • infrahub_sdk/node/node.py
tests/**/*.py

📄 CodeRabbit inference engine (tests/AGENTS.md)

tests/**/*.py: Use httpx_mock fixture for HTTP mocking in tests instead of making real HTTP requests
Do not add @pytest.mark.asyncio decorator to async test functions (async auto-mode is globally enabled)

Files:

  • tests/unit/sdk/test_node.py
tests/unit/**/*.py

📄 CodeRabbit inference engine (tests/AGENTS.md)

Unit tests must be fast, mocked, and have no external dependencies

Files:

  • tests/unit/sdk/test_node.py
**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{md,mdx}: Use text language for directory structure code blocks in markdown documentation
Add blank lines before and after lists in markdown documentation
Always specify language in fenced code blocks in markdown documentation

Files:

  • changelog/630.fixed.md
infrahub_sdk/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Follow async/sync dual pattern for new features in the Python SDK

Files:

  • infrahub_sdk/node/node.py
🧠 Learnings (3)
📓 Common learnings
Learnt from: wvandeun
Repo: opsmill/infrahub-sdk-python PR: 637
File: infrahub_sdk/operation.py:74-76
Timestamp: 2025-11-25T13:23:15.190Z
Learning: In infrahub_sdk/operation.py, the recursive=True parameter in _process_relationships is a temporary workaround to access Proposed Changes data. This will be replaced with proper object-level metadata implementation in version 1.7.
📚 Learning: 2025-12-10T17:13:08.136Z
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:08.136Z
Learning: Applies to infrahub_sdk/client.py : Always provide both async and sync versions of client implementations in InfrahubClient

Applied to files:

  • tests/unit/sdk/test_node.py
📚 Learning: 2025-11-25T13:23:15.190Z
Learnt from: wvandeun
Repo: opsmill/infrahub-sdk-python PR: 637
File: infrahub_sdk/operation.py:74-76
Timestamp: 2025-11-25T13:23:15.190Z
Learning: In infrahub_sdk/operation.py, the recursive=True parameter in _process_relationships is a temporary workaround to access Proposed Changes data. This will be replaced with proper object-level metadata implementation in version 1.7.

Applied to files:

  • infrahub_sdk/node/node.py
🧬 Code graph analysis (2)
tests/unit/sdk/test_node.py (1)
infrahub_sdk/node/node.py (1)
  • _generate_input_data (195-284)
infrahub_sdk/node/node.py (6)
infrahub_sdk/node/attribute.py (1)
  • _generate_input_data (74-105)
infrahub_sdk/node/property.py (1)
  • _generate_input_data (23-24)
infrahub_sdk/node/related_node.py (1)
  • _generate_input_data (128-145)
infrahub_sdk/node/relationship.py (1)
  • _generate_input_data (59-60)
infrahub_sdk/protocols_base.py (1)
  • _generate_input_data (35-35)
infrahub_sdk/yaml.py (1)
  • data (147-150)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.14)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (5)
infrahub_sdk/node/node.py (1)

195-242: LGTM! Clean implementation of the optional relationship fix.

The conditional logic correctly distinguishes between new and existing nodes:

  • For existing nodes (self._existing is True): None is included to allow clearing relationships
  • For new nodes: the field is omitted to allow object template defaults to apply

The added comment clearly documents the intent of this behavior.

tests/unit/sdk/test_node.py (3)

1405-1435: Well-structured test for the existing node behavior.

The test correctly validates that:

  1. Existing nodes (those with an id) include None for uninitialized optional relationships
  2. Both sync and async clients are covered

The docstring clearly explains the test's purpose, and the use of the BothClients fixture follows the pattern established in other tests.


1680-1696: Test expectations correctly updated.

The expected output for new nodes now omits uninitialized optional relationships, aligning with the implementation change that allows object template defaults to apply.


1361-1375: Test correctly reflects new behavior for new nodes.

The expected output no longer includes primary_tag: None for new nodes, which aligns with the implementation change that omits optional uninitialized relationships to allow object template defaults to apply.

changelog/630.fixed.md (1)

1-1: Clear and accurate changelog entry.

The entry concisely explains the issue (explicit null values for uninitialized optional relationships) and its impact (preventing backend template defaults from applying).

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