Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[builder] lookback period with months fails #48707

Open
LucasSegersFabro opened this issue Nov 26, 2024 · 0 comments
Open

[builder] lookback period with months fails #48707

LucasSegersFabro opened this issue Nov 26, 2024 · 0 comments

Comments

@LucasSegersFabro
Copy link

Topic

lookback period with with a month (P1M) fails

Relevant information

Airbyte info:

  • kubernetes deployment
  • OSS version 1.2.0

Issue

When building an incremental sync connection with the UI builder, I needed to use a P6M lookback period
However, when using a month ("M") lookback period, the builder fails to test with the following stacktrace:

Error: year 0 is out of range

Traceback (most recent call last):
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py", line 133, in read
    yield from self._read_stream(
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py", line 239, in _read_stream
    for record_data_or_message in record_iterator:
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/streams/core.py", line 176, in read
    checkpoint_reader = self._get_checkpoint_reader(
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/declarative_stream.py", line 194, in _get_checkpoint_reader
    mappings_or_slices = self.stream_slices(
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/declarative_stream.py", line 159, in stream_slices
    return self.retriever.stream_slices()
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/retrievers/simple_retriever.py", line 482, in stream_slices
    return islice(super().stream_slices(), self.maximum_number_of_slices)
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/retrievers/simple_retriever.py", line 429, in stream_slices
    return self.stream_slicer.stream_slices()
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py", line 170, in stream_slices
    start_datetime = self._calculate_earliest_possible_value(self.select_best_end_datetime())
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py", line 182, in _calculate_earliest_possible_value
    cursor_datetime = self._calculate_cursor_datetime_from_state(self.get_stream_state()) - lookback_delta
  File "/home/airbyte/.pyenv/versions/3.10.14/lib/python3.10/site-packages/isodate/duration.py", line 269, in __rsub__
    newdt = other.replace(
ValueError: year 0 is out of range

The issue is fixed if I use a day-based lookback window like "P180D" ✅

Additional details:

Incremental sync configuration:

type: DatetimeBasedCursor
cursor_field: _synced_when
lookback_window: P1M
cursor_datetime_formats:
  - '%Y-%m-%d'
datetime_format: '%Y-%m-%d'
start_datetime:
  type: MinMaxDatetime
  datetime: '{{ config[''data_inicio''] }}'
  datetime_format: '%Y-%m-%d'
start_time_option:
  inject_into: request_parameter
  field_name: emission_start
  type: RequestOption
end_time_option:
  inject_into: request_parameter
  field_name: emission_end
  type: RequestOption
end_datetime:
  type: MinMaxDatetime
  datetime: '{{ now_utc().strftime(''%Y-%m-%d'') }}'
  datetime_format: '%Y-%m-%d'

_synced_when field is added through transformations:

- type: AddFields
  fields:
    - path:
        - _synced_when
      value: '{{ format_datetime(now_utc(), ''%Y-%m-%d'') }}'

config['data_inicio'] is a "date" user input, tested with the value '2023-01-01'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants