A context manager for opening and managing a transaction.Args:
- key: An identifier to use for the transaction
- store: The store to use for persisting the transaction result. If not provided,
a default store will be used based on the current run context.
- commit_mode: The commit mode controlling when the transaction and
child transactions are committed
- overwrite: Whether to overwrite an existing transaction record in the store
- write_on_commit: Whether to write the result to the store on commit. If not provided,
will default will be determined by the current run context. If no run context is
available, the value of PREFECT_RESULTS_PERSIST_BY_DEFAULT will be used.
An asynchronous context manager for opening and managing an asynchronous transaction.Args:
- key: An identifier to use for the transaction
- store: The store to use for persisting the transaction result. If not provided,
a default store will be used based on the current run context.
- commit_mode: The commit mode controlling when the transaction and
child transactions are committed
- overwrite: Whether to overwrite an existing transaction record in the store
- write_on_commit: Whether to write the result to the store on commit. If not provided,
the default will be determined by the current run context. If no run context is
available, the value of PREFECT_RESULTS_PERSIST_BY_DEFAULT will be used.
get(self, name: str, default: Any = NotSet) -> Any
Get a stored value from the transaction.Child transactions will return values from their parents unless a value with
the same name is set in the child transaction.Direct changes to returned values will not update the stored value. To update the
stored value, use the set method.Args:
name: The name of the value to get
default: The default value to return if the value is not found
Returns:
The value from the transaction
Examples:Get a value from the transaction:
with transaction() as txn: txn.set("key", "value") ... assert txn.get("key") == "value"
Get a value from a parent transaction:
with transaction() as parent: parent.set("key", "parent_value") with transaction() as child: assert child.get("key") == "parent_value"
Update a stored value:
with transaction() as txn: txn.set("key", [1, 2, 3]) value = txn.get("key") value.append(4) # Stored value is not updated until `.set` is called assert value == [1, 2, 3, 4] assert txn.get("key") == [1, 2, 3] txn.set("key", value) assert txn.get("key") == [1, 2, 3, 4]
get(self, name: str, default: Any = NotSet) -> Any
Get a stored value from the transaction.Child transactions will return values from their parents unless a value with
the same name is set in the child transaction.Direct changes to returned values will not update the stored value. To update the
stored value, use the set method.Args:
name: The name of the value to get
default: The default value to return if the value is not found
Returns:
The value from the transaction
Examples:Get a value from the transaction:
with transaction() as txn: txn.set("key", "value") ... assert txn.get("key") == "value"
Get a value from a parent transaction:
with transaction() as parent: parent.set("key", "parent_value") with transaction() as child: assert child.get("key") == "parent_value"
Update a stored value:
with transaction() as txn: txn.set("key", [1, 2, 3]) value = txn.get("key") value.append(4) # Stored value is not updated until `.set` is called assert value == [1, 2, 3, 4] assert txn.get("key") == [1, 2, 3] txn.set("key", value) assert txn.get("key") == [1, 2, 3, 4]
get(self, name: str, default: Any = NotSet) -> Any
Get a stored value from the transaction.Child transactions will return values from their parents unless a value with
the same name is set in the child transaction.Direct changes to returned values will not update the stored value. To update the
stored value, use the set method.Args:
name: The name of the value to get
default: The default value to return if the value is not found
Returns:
The value from the transaction
Examples:Get a value from the transaction:
with transaction() as txn: txn.set("key", "value") ... assert txn.get("key") == "value"
Get a value from a parent transaction:
with transaction() as parent: parent.set("key", "parent_value") with transaction() as child: assert child.get("key") == "parent_value"
Update a stored value:
with transaction() as txn: txn.set("key", [1, 2, 3]) value = txn.get("key") value.append(4) # Stored value is not updated until `.set` is called assert value == [1, 2, 3, 4] assert txn.get("key") == [1, 2, 3] txn.set("key", value) assert txn.get("key") == [1, 2, 3, 4]