Skip to content

Commit 38e43d7

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 e02fb06 commit 38e43d7

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
@@ -629,14 +629,14 @@ async def _run(task: Task):
629629
):
630630
initialized_backfill_state = resource.initial_state.backfill
631631
initialized_backfill_state.cutoff = state.inc.cursor
632-
state.backfill = initialized_backfill_state
632+
state.backfill = initialized_backfill_state.model_copy(deep=True)
633633
# In all other cases, wipe the state back to the initial state.
634634
else:
635-
state = resource.initial_state
635+
state = resource.initial_state.model_copy(deep=True)
636636

637637
state.is_connector_initiated = True
638638
else:
639-
state = resource.initial_state
639+
state = resource.initial_state.model_copy(deep=True)
640640

641641
state.last_initialized = NOW
642642

0 commit comments

Comments
 (0)