Skip to content

Commit f7f2420

Browse files
fix: use flexible datetime parsing for start_date in file-based connectors
Replace strict regex pattern with ab_datetime_try_parse validator to accept any valid ISO8601/RFC3339 datetime format. This fixes issues where valid datetime strings like '2025-01-01T00:00:00Z' (without microseconds) were incorrectly rejected. Fixes: airbytehq/oncall#9390 Co-Authored-By: AJ Steers <aj@airbyte.io>
1 parent 313db66 commit f7f2420

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

airbyte_cdk/sources/file_based/config/abstract_file_based_spec.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from typing import Any, Dict, List, Literal, Optional, Union
88

99
import dpath
10-
from pydantic.v1 import AnyUrl, BaseModel, Field
10+
from pydantic.v1 import AnyUrl, BaseModel, Field, validator
1111

1212
from airbyte_cdk import OneOfOptionConfig
1313
from airbyte_cdk.sources.file_based.config.file_based_stream_config import FileBasedStreamConfig
1414
from airbyte_cdk.sources.specs.transfer_modes import DeliverPermissions
1515
from airbyte_cdk.sources.utils import schema_helpers
16+
from airbyte_cdk.utils.datetime_helpers import ab_datetime_try_parse
1617

1718

1819
class DeliverRecords(BaseModel):
@@ -55,11 +56,27 @@ class AbstractFileBasedSpec(BaseModel):
5556
description="UTC date and time in the format 2017-01-25T00:00:00.000000Z. Any file modified before this date will not be replicated.",
5657
examples=["2021-01-01T00:00:00.000000Z"],
5758
format="date-time",
58-
pattern="^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6}Z$",
59-
pattern_descriptor="YYYY-MM-DDTHH:mm:ss.SSSSSSZ",
6059
order=1,
6160
)
6261

62+
@validator("start_date", pre=True)
63+
def validate_start_date(cls, v: Optional[str]) -> Optional[str]:
64+
"""Validate that start_date is a parseable datetime string.
65+
66+
Uses ab_datetime_try_parse which accepts any common ISO8601/RFC3339 format,
67+
including formats with or without microseconds (e.g., both
68+
'2021-01-01T00:00:00Z' and '2021-01-01T00:00:00.000000Z' are valid).
69+
"""
70+
if v is None:
71+
return v
72+
parsed = ab_datetime_try_parse(v)
73+
if parsed is None:
74+
raise ValueError(
75+
f"'{v}' is not a valid datetime string. "
76+
"Please use a format like '2021-01-01T00:00:00Z' or '2021-01-01T00:00:00.000000Z'."
77+
)
78+
return v
79+
6380
streams: List[FileBasedStreamConfig] = Field(
6481
title="The list of streams to sync",
6582
description='Each instance of this configuration defines a <a href="https://docs.airbyte.com/cloud/core-concepts#stream">stream</a>. Use this to define which files belong in the stream, their format, and how they should be parsed and validated. When sending data to warehouse destination such as Snowflake or BigQuery, each stream is a separate table.',

0 commit comments

Comments
 (0)