Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ def _migrate_child_state_to_parent_state(self, stream_state: StreamState) -> Str
# Ignore per-partition states or invalid formats.
if isinstance(substream_state, (list, dict)) or len(substream_state_values) != 1:
# If a global state is present under the key "state", use its first value.
if "state" in stream_state and isinstance(stream_state["state"], dict):
if (
"state" in stream_state
and isinstance(stream_state["state"], dict)
and stream_state["state"] != {}
):
substream_state = list(stream_state["state"].values())[0]
else:
return {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,17 @@ def test_substream_partition_router_invalid_parent_record_type():
},
{"parent_stream_cursor": "2023-05-27T00:00:00Z"},
),
# Case 7: Migrate child state to parent state but child state is empty
(
{
"state": {},
"states": [],
"parent_state": {"posts": {}},
"lookback_window": 1,
"use_global_cursor": False,
},
{},
),
],
ids=[
"empty_initial_state",
Expand All @@ -481,6 +492,7 @@ def test_substream_partition_router_invalid_parent_record_type():
"initial_state_no_parent_per_partition_state",
"initial_state_with_parent_state",
"initial_state_no_parent_global_state_declarative",
"initial_state_no_parent_and_no_child",
],
)
def test_set_initial_state(initial_state, expected_parent_state):
Expand Down
Loading