Skip to content

Commit afad0ce

Browse files
fix: Handle Pydantic Union type coercion for page_size in OffsetIncrement and PageIncrement
Co-Authored-By: alfredo.garcia@airbyte.io <freddy.garcia7.fg@gmail.com>
1 parent 3226f7c commit afad0ce

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,8 +2927,14 @@ def create_offset_increment(
29272927
else None
29282928
)
29292929

2930+
# Pydantic v1 Union type coercion can convert int to string depending on Union order.
2931+
# If page_size is a string that represents an integer (not an interpolation), convert it back.
2932+
page_size = model.page_size
2933+
if isinstance(page_size, str) and page_size.isdigit():
2934+
page_size = int(page_size)
2935+
29302936
return OffsetIncrement(
2931-
page_size=model.page_size,
2937+
page_size=page_size,
29322938
config=config,
29332939
decoder=decoder_to_use,
29342940
extractor=extractor,
@@ -2940,8 +2946,14 @@ def create_offset_increment(
29402946
def create_page_increment(
29412947
model: PageIncrementModel, config: Config, **kwargs: Any
29422948
) -> PageIncrement:
2949+
# Pydantic v1 Union type coercion can convert int to string depending on Union order.
2950+
# If page_size is a string that represents an integer (not an interpolation), convert it back.
2951+
page_size = model.page_size
2952+
if isinstance(page_size, str) and page_size.isdigit():
2953+
page_size = int(page_size)
2954+
29432955
return PageIncrement(
2944-
page_size=model.page_size,
2956+
page_size=page_size,
29452957
config=config,
29462958
start_from_page=model.start_from_page or 0,
29472959
inject_on_first_request=model.inject_on_first_request or False,

0 commit comments

Comments
 (0)