Tables.data_transaction(scenario_name=None, *, allow_nested=True, tables=None)
Create a data transaction to batch several data loading operations.- It is more efficient than doing each
load()one after the other, especially when usingload_async()to load data concurrently in multiple tables. - It avoids possibly incorrect intermediate states (e.g. if loading some new data requires dropping existing rows first).
- If an exception is raised during a data transaction, it will be rolled back and the changes made until the exception will be discarded.
Data transactions cannot be mixed with:
- Long-running data operations such as
stream(). - Data model operations such as
create_table(),join(), or defining a new measure. - Operations on parameter tables created from
create_parameter_hierarchy_from_members()andcreate_parameter_simulation(). - Operations on other source scenarios than the one the transaction is started on.
- Parameters:
-
allow_nested (bool) –
Whether to allow starting this transaction inside an already running one.
When
False, an error will be raised if this transaction is started while another transaction is already running, regardless of that outer transaction’s value of allow_nested. The benefit of passingFalseis that changes made in this transaction are guaranteed, if not rolled back, to be visible to the statements outside the transaction. The drawback is that it prevents splitting transaction steps in small composable functions. When nested transactions are allowed, changes made by inner transactions contribute transparently to the outer transaction and will only be committed when the outer transaction’s context exits. - scenario_name (str | None) – The name of the source scenario impacted by all the table operations inside the transaction.
-
tables (Set *[*HasIdentifier *[*TableIdentifier ] | TableIdentifier ] | None) – The tables that can be affected by this transaction.
Tables transitively joined with these tables will be locked too.
Transactions locking disjoint sets of tables execute concurrently.
When
None, all tables are locked.
-
allow_nested (bool) –
Whether to allow starting this transaction inside an already running one.
When
- Return type: AbstractContextManager[None]
Example
See also:
data_model_transaction().