Skip to content

Commit a73ab6c

Browse files
committed
estuary-cdk: prevent state mutations by deep copying initial_state`
Previously when initializing the state of a binding, the CDK was directly referencing the `initial_state` of the binding and any modifications made to the binding's `state` would also be reflected in the `initial_state`. While this works when all bindings have their own distinct `initial_state`s, this would cause unintended mutations if the same `initial_state` was used for multiple bindings. Instead, the CDK now creates a deep copy of the `initial_state` when initializing a binding's `state`. This prevents mutations to `state` from affecting `initial_state`.
1 parent f4fb7e4 commit a73ab6c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

estuary-cdk/estuary_cdk/capture/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,14 @@ async def _run(task: Task):
573573
):
574574
initialized_backfill_state = resource.initial_state.backfill
575575
initialized_backfill_state.cutoff = state.inc.cursor
576-
state.backfill = initialized_backfill_state
576+
state.backfill = initialized_backfill_state.model_copy(deep=True)
577577
# In all other cases, wipe the state back to the initial state.
578578
else:
579-
state = resource.initial_state
579+
state = resource.initial_state.model_copy(deep=True)
580580

581581
state.is_connector_initiated = True
582582
else:
583-
state = resource.initial_state
583+
state = resource.initial_state.model_copy(deep=True)
584584

585585
state.last_initialized = NOW
586586

0 commit comments

Comments
 (0)