Skip to content
Merged
23 changes: 20 additions & 3 deletions airbyte_cdk/sources/file_based/config/abstract_file_based_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from typing import Any, Dict, List, Literal, Optional, Union

import dpath
from pydantic.v1 import AnyUrl, BaseModel, Field
from pydantic.v1 import AnyUrl, BaseModel, Field, validator

from airbyte_cdk import OneOfOptionConfig
from airbyte_cdk.sources.file_based.config.file_based_stream_config import FileBasedStreamConfig
from airbyte_cdk.sources.specs.transfer_modes import DeliverPermissions
from airbyte_cdk.sources.utils import schema_helpers
from airbyte_cdk.utils.datetime_helpers import ab_datetime_try_parse


class DeliverRecords(BaseModel):
Expand Down Expand Up @@ -55,11 +56,27 @@ class AbstractFileBasedSpec(BaseModel):
description="UTC date and time in the format 2017-01-25T00:00:00.000000Z. Any file modified before this date will not be replicated.",
examples=["2021-01-01T00:00:00.000000Z"],
format="date-time",
pattern="^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6}Z$",
Comment thread
aaronsteers marked this conversation as resolved.
pattern_descriptor="YYYY-MM-DDTHH:mm:ss.SSSSSSZ",
order=1,
)

@validator("start_date", pre=True)
def validate_start_date(cls, v: Optional[str]) -> Optional[str]:
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
"""Validate that start_date is a parseable datetime string.

Uses ab_datetime_try_parse which accepts any common ISO8601/RFC3339 format,
including formats with or without microseconds (e.g., both
'2021-01-01T00:00:00Z' and '2021-01-01T00:00:00.000000Z' are valid).
"""
if v is None:
return v
parsed = ab_datetime_try_parse(v)
if parsed is None:
raise ValueError(
f"'{v}' is not a valid datetime string. "
"Please use a format like '2021-01-01T00:00:00Z' or '2021-01-01T00:00:00.000000Z'."
)
return v
Comment thread
aaronsteers marked this conversation as resolved.

streams: List[FileBasedStreamConfig] = Field(
title="The list of streams to sync",
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.',
Expand Down
Loading