fix(node): include user keys on fetch to avoid spurious changed status#334
Merged
Conversation
Pass `include=list(user_data_keys)` to `fetch_single_node` in `_get_object` so every attribute and relationship the user intends to update is initialized on the fetched node. Without this, the SDK skips uninitialized relationships in `_generate_input_data()` (`if not rel.initialized: continue`), so the "before" snapshot used for diff comparison misses keys that the "after" snapshot has after `setattr`. The resulting `dict_hash` mismatch reports `changed: true` for a no-op idempotent re-run. The `or None` fallback preserves default fetch behavior when the user provides only identifier keys (e.g. `state: absent`).
Deploying infrahub-ansible with
|
| Latest commit: |
0f977e1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://30d08f5c.infrahub-ansible.pages.dev |
| Branch Preview URL: | https://fix-diff-include-relationshi.infrahub-ansible.pages.dev |
petercrocker
approved these changes
Jun 11, 2026
Regression guard for the spurious changed-status fix: the original include-on-fetch fix (6f1315e) was silently dropped during the diff rework (0142ad6) because nothing asserted the fetch_single_node call arguments. These tests fail if the include derivation is removed again. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
The
nodemodule can reportchanged: trueon idempotent re-runs of a task whosedataincludes a relationship. Re-applying the exact same payload should be a no-op but currently flips status tochanged.Root cause
_get_objectcallsfetch_single_nodewithout anincludelist, so cardinality-MANY non-attribute/non-parent relationships are not requested in the GraphQL query and stay uninitialized on the returned node. When_update_objectbuilds the diff:serialized_before = node._generate_input_data()— skips uninitialized relationships (SDK:if not rel.initialized: continue).setattr(node, rel_name, …)initializes the relationship.serialized_after = node._generate_input_data()— now includes the relationship.dict_hash(serialized_before) != dict_hash(serialized_after)even when the underlying value matches → falsechanged: true.This regressed when the original include-on-fetch fix (commit
6f1315e) was removed during the diff rework in0142ad6.Fix
In
_get_object, deriveincludefrom the user-provideddatakeys (excludingid/hfidwhich are not schema fields) and pass it tofetch_single_node. Empty list collapses toNoneso thestate: absentpath and identifier-only lookups keep their default fetch behavior.Test plan
pytest tests/unit/plugins/module_utils/test_node.py→ 23/23sandbox.infrahub.app:Create tag1→ changedUpdate tag1→ changedExisting tag1→ ok (not changed) ← the idempotency assertion this PR restoresDelete tag1→ changedDelete tag1(already absent) → okSummary by cubic
Fixes false changed status in the
nodemodule by fetching nodes with the user’s fields included. Adds regression tests to prevent this idempotency issue from returning.includefrom userdatakeys (excludingidandhfid) and pass tofetch_single_node.state: absentand lookup behavior.includecontains user keys and defaults toNonefor identifier-only data.Written for commit 0f977e1. Summary will update on new commits.