Skip to content

Commit af400e5

Browse files
committed
fix substreampartitionrouter state migration from child when it is empty
1 parent 837913f commit af400e5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _migrate_child_state_to_parent_state(self, stream_state: StreamState) -> Str
374374
# Ignore per-partition states or invalid formats.
375375
if isinstance(substream_state, (list, dict)) or len(substream_state_values) != 1:
376376
# If a global state is present under the key "state", use its first value.
377-
if "state" in stream_state and isinstance(stream_state["state"], dict):
377+
if "state" in stream_state and isinstance(stream_state["state"], dict) and stream_state["state"] != {}:
378378
substream_state = list(stream_state["state"].values())[0]
379379
else:
380380
return {}

unit_tests/sources/declarative/partition_routers/test_substream_partition_router.py

+14
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,19 @@ def test_substream_partition_router_invalid_parent_record_type():
473473
},
474474
{"parent_stream_cursor": "2023-05-27T00:00:00Z"},
475475
),
476+
# Case 7: Migrate child state to parent state but child state is empty
477+
(
478+
{
479+
"state": {},
480+
"states": [],
481+
"parent_state": {
482+
"posts": {}
483+
},
484+
"lookback_window": 1,
485+
"use_global_cursor": False
486+
},
487+
{},
488+
),
476489
],
477490
ids=[
478491
"empty_initial_state",
@@ -481,6 +494,7 @@ def test_substream_partition_router_invalid_parent_record_type():
481494
"initial_state_no_parent_per_partition_state",
482495
"initial_state_with_parent_state",
483496
"initial_state_no_parent_global_state_declarative",
497+
"initial_state_no_parent_and_no_child",
484498
],
485499
)
486500
def test_set_initial_state(initial_state, expected_parent_state):

0 commit comments

Comments
 (0)