Skip to content

Commit 2ab1416

Browse files
committed
fix Pydantic v1 Union type coercion
1 parent ebe431e commit 2ab1416

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,14 +1554,18 @@ def create_concurrent_cursor_from_incrementing_count_cursor(
15541554
f"Expected {model_type.__name__} component, but received {incrementing_count_cursor_model.__class__.__name__}"
15551555
)
15561556

1557-
interpolated_start_value = (
1558-
InterpolatedString.create(
1559-
incrementing_count_cursor_model.start_value, # type: ignore
1557+
start_value: Union[int, str, None] = incrementing_count_cursor_model.start_value
1558+
# Pydantic Union type coercion can convert int 0 to string '0' depending on Union order.
1559+
# We need to handle both int and str representations of numeric values.
1560+
# Evaluate the InterpolatedString and convert to int for the ConcurrentCursor.
1561+
if start_value is not None:
1562+
interpolated_start_value = InterpolatedString.create(
1563+
str(start_value), # Ensure we pass a string to InterpolatedString.create
15601564
parameters=incrementing_count_cursor_model.parameters or {},
15611565
)
1562-
if incrementing_count_cursor_model.start_value
1563-
else 0
1564-
)
1566+
evaluated_start_value: int = int(interpolated_start_value.eval(config=config))
1567+
else:
1568+
evaluated_start_value = 0
15651569

15661570
cursor_field = self._get_catalog_defined_cursor_field(
15671571
stream_name=stream_name,
@@ -1593,7 +1597,7 @@ def create_concurrent_cursor_from_incrementing_count_cursor(
15931597
connector_state_converter=connector_state_converter,
15941598
cursor_field=cursor_field,
15951599
slice_boundary_fields=None,
1596-
start=interpolated_start_value, # type: ignore # Having issues w/ inspection for GapType and CursorValueType as shown in existing tests. Confirmed functionality is working in practice
1600+
start=evaluated_start_value,
15971601
end_provider=connector_state_converter.get_end_provider(), # type: ignore # Having issues w/ inspection for GapType and CursorValueType as shown in existing tests. Confirmed functionality is working in practice
15981602
)
15991603

0 commit comments

Comments
 (0)