Skip to content

Commit 90a247f

Browse files
committed
extra test cases and change types
1 parent ea877a8 commit 90a247f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

airbyte_cdk/sources/declarative/retrievers/simple_retriever.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def _read_pages(
405405
)
406406
)
407407
if merge_key:
408-
deep_merge(merged_records[merge_key], current_record)
408+
_deep_merge(merged_records[merge_key], current_record)
409409
else:
410410
# We should still emit records even if the record did not have a merge key
411411
last_page_size += 1
@@ -624,16 +624,22 @@ def _to_partition_key(to_serialize: Any) -> str:
624624
return json.dumps(to_serialize, indent=None, separators=(",", ":"), sort_keys=True)
625625

626626

627-
def deep_merge(target: Dict[str, Any], source: Union[Record, Dict[str, Any]]) -> None:
627+
def _deep_merge(
628+
target: MutableMapping[str, Any], source: Union[Record, MutableMapping[str, Any]]
629+
) -> None:
628630
"""
629631
Recursively merge two dictionaries, combining nested dictionaries instead of overwriting them.
630632
631633
:param target: The dictionary to merge into (modified in place)
632634
:param source: The dictionary to merge from
633635
"""
634636
for key, value in source.items():
635-
if key in target and isinstance(target[key], dict) and isinstance(value, dict):
636-
deep_merge(target[key], value)
637+
if (
638+
key in target
639+
and isinstance(target[key], MutableMapping)
640+
and isinstance(value, MutableMapping)
641+
):
642+
_deep_merge(target[key], value)
637643
else:
638644
target[key] = value
639645

unit_tests/sources/declarative/retrievers/test_simple_retriever.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,10 @@ def test_simple_retriever_with_additional_query_properties():
11511151
"dict_field": {
11521152
"key1": "value1",
11531153
"key2": "value2",
1154+
"affiliation": {
1155+
"company": "cradle",
1156+
"industry": "pharmaceutical",
1157+
},
11541158
},
11551159
},
11561160
associated_slice=None,
@@ -1174,6 +1178,7 @@ def test_simple_retriever_with_additional_query_properties():
11741178
"last_name": "kurashiki",
11751179
"nonary": "second",
11761180
"bracelet": "6",
1181+
"allies": ["aoi_kurashiki"],
11771182
},
11781183
associated_slice=None,
11791184
stream_name=stream_name,
@@ -1224,7 +1229,7 @@ def test_simple_retriever_with_additional_query_properties():
12241229
"id": "a",
12251230
"first_name": "gentarou",
12261231
"last_name": "hongou",
1227-
"dict_field": {"key1": "value1"},
1232+
"dict_field": {"key1": "value1", "affiliation": {"company": "cradle"}},
12281233
},
12291234
associated_slice=None,
12301235
stream_name=stream_name,
@@ -1235,7 +1240,12 @@ def test_simple_retriever_with_additional_query_properties():
12351240
stream_name=stream_name,
12361241
),
12371242
Record(
1238-
data={"id": "c", "first_name": "akane", "last_name": "kurashiki"},
1243+
data={
1244+
"id": "c",
1245+
"first_name": "akane",
1246+
"last_name": "kurashiki",
1247+
"allies": ["aoi_kurashiki"],
1248+
},
12391249
associated_slice=None,
12401250
stream_name=stream_name,
12411251
),
@@ -1276,7 +1286,7 @@ def test_simple_retriever_with_additional_query_properties():
12761286
"id": "a",
12771287
"nonary": "second",
12781288
"bracelet": "1",
1279-
"dict_field": {"key2": "value2"},
1289+
"dict_field": {"key2": "value2", "affiliation": {"industry": "pharmaceutical"}},
12801290
},
12811291
associated_slice=None,
12821292
stream_name=stream_name,

0 commit comments

Comments
 (0)