Skip to content

Commit a67a6cf

Browse files
fix: treat empty string cursor field as no cursor field (#875)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 49ff36e commit a67a6cf

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4339,8 +4339,14 @@ def _get_catalog_defined_cursor_field(
43394339
configured_stream = self._stream_name_to_configured_stream.get(stream_name)
43404340

43414341
# Depending on the operation is being performed, there may not be a configured stream yet. In this
4342-
# case we return None which will then use the default cursor field defined on the cursor model
4343-
if not configured_stream or not configured_stream.cursor_field:
4342+
# case we return None which will then use the default cursor field defined on the cursor model.
4343+
# We also treat cursor_field: [""] (list with empty string) as no cursor field, since this can
4344+
# occur when the platform serializes "no cursor configured" streams incorrectly.
4345+
if (
4346+
not configured_stream
4347+
or not configured_stream.cursor_field
4348+
or not configured_stream.cursor_field[0]
4349+
):
43444350
return None
43454351
elif len(configured_stream.cursor_field) > 1:
43464352
raise ValueError(

airbyte_cdk/sources/streams/concurrent/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def get_cursor_field_from_stream(stream: Stream) -> Optional[str]:
3434
raise ValueError(
3535
f"Nested cursor fields are not supported. Got {stream.cursor_field} for {stream.name}"
3636
)
37-
elif len(stream.cursor_field) == 0:
37+
elif len(stream.cursor_field) == 0 or not stream.cursor_field[0]:
38+
# Treat cursor_field: [""] (list with empty string) as no cursor field
3839
return None
3940
else:
4041
return stream.cursor_field[0]

unit_tests/sources/declarative/parsers/test_model_to_component_factory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5051,6 +5051,12 @@ def test_create_stream_with_multiple_schema_loaders():
50515051
"updated_at",
50525052
id="test_allow_catalog_defined_cursor_field_false_defaults_to_stream_defined_cursor_field",
50535053
),
5054+
pytest.param(
5055+
True,
5056+
"",
5057+
"updated_at",
5058+
id="test_empty_string_catalog_cursor_field_defaults_to_stream_defined_cursor_field",
5059+
),
50545060
],
50555061
)
50565062
def test_catalog_defined_cursor_field(

0 commit comments

Comments
 (0)