-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Component
Python SDK
Describe the Feature Request
When saving a node (especially with allow_upsert=True), the SDK currently includes all fields in the GraphQL mutation payload, not just fields that have been modified. This can lead to unintended side effects, such as:
- Sending
nullfor unset optional relationships (e.g.parent: nullfor hierarchical nodes), causing server-side errors - Overwriting values that were set by other processes, object templates, or server defaults
- Unnecessary data in mutation payloads increasing request size and processing time
The SDK should implement dirty/change tracking so that _generate_input_data() only includes fields that have been explicitly set or modified since the node was created or fetched.
PR #810 addressed a specific instance of this problem (hierarchical relationships), but the underlying issue applies more broadly to all attributes and relationships.
Describe the Use Case
-
Upsert without overwriting: A user fetches a node, modifies one attribute, and saves it. Currently all fields are sent, potentially overwriting concurrent changes to other fields. Only the modified attribute should be included in the mutation.
-
Object template defaults: When creating a new node with
allow_upsert=True, unset optional fields are sent asnull, which can override defaults that would otherwise be applied by object templates on the server side. -
Concurrent workflows: Multiple scripts or users may modify different fields on the same node. Without change tracking, each save overwrites the entire object, creating race conditions.
Additional Information
- Related PR: Fix: exclude uninitialized hierarchy relationships from mutation data #810 (fixes the specific case of hierarchical relationships)
- The fix in PR Fix: exclude uninitialized hierarchy relationships from mutation data #810 skips hierarchy relationships unless explicitly initialized — this pattern should be generalized to all fields
- Key area of the codebase:
infrahub_sdk/node/node.py—_generate_input_data()method - A possible approach is to track a
_dirtyset on each node that records which attributes/relationships have been explicitly set or modified, and filter_generate_input_data()output accordingly