infrahub_sdk.node.attribute
Classes
Attribute
Represents an attribute of a Node, including its schema, value, and properties.
An Attribute wraps a single attribute on an :class:InfrahubNode. It tracks the
current value, the metadata properties (source, owner, is_protected, ...),
and whether the value has been mutated since the node was loaded. Mutation tracking is
used by InfrahubNode.update() to send only the changed fields to the API.
Attributes:
name: The name of the attribute.id: The unique identifier of the attribute, when known.value: The current attribute value. Setting this marks the attribute as mutated.value_has_been_mutated: True whenvaluehas been assigned after construction.is_loaded: True when the node's data contained the attribute, a value was assigned since, the attribute does not belong to a node, or the node has noidyet.is_default: True when the value comes from the schema default.is_from_profile: True when the value is inherited from a profile.is_inherited: True when the attribute is inherited from a generic.is_protected: True when the attribute is protected from modification.updated_at: ISO-8601 timestamp of the most recent update.source: The node that supplied this attribute value.owner: The node that owns this attribute.updated_by: The account that performed the most recent update.
Methods:
value
value(self) -> Any
Return the attribute value.
Raises:
FieldNotLoadedError: The node was queried withonlyand the attribute was not fetched.
value
value(self, value: Any) -> None
is_loaded
is_loaded(self) -> bool
Return whether this attribute holds a value from its node's data or from an assignment.
Never raises and sends no request.
Returns:
Truewhen the data the node was built from contained the attribute, when a value- was assigned since, when the attribute does not belong to a node, or when its node has no
idyet.Falseotherwise.
attach_to_pool
attach_to_pool(self, pool: CoreNodeBase | str) -> None
Attach the number this attribute holds to a number pool when the node is next saved.
The pool then tracks the number as one a user provided, without allocating a new one.
Args:
pool: The number pool node, or its ID.
Raises:
ValueError: If the attribute holds no number, or ifpoolis a node that is not a resource pool or has not been saved.
detach_from_pool
detach_from_pool(self) -> None
Detach the number this attribute holds from its number pool when the node is next saved.
The attribute keeps its number, and the pool stops tracking it.
is_from_pool_attribute
is_from_pool_attribute(self) -> bool
Check whether this attribute's value is sourced from a resource pool.
This reflects only the pool requests made through this object. For a node fetched from the server, query it
with property=True and read the attribute's source, which is the number pool tracking the value.
Returns:
- True if the attribute value is a resource pool node or was explicitly allocated from a pool.
is_unresolved_pool_attribute
is_unresolved_pool_attribute(self) -> bool
Return True when pool-backed but no concrete scalar value is available yet.
A pool-backed attribute is unresolved when:
- its value is a pool node object (the pool reference itself, not an allocated scalar), or
- its value is None and the from_pool allocation dict is set.
An attribute whose _from_pool dict is set but which holds a number, either the one allocated by a prior save or one given to attach to the pool, is considered resolved.