-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
SAT: add threshold_days
incremental test option
#12715
Conversation
def compare_cursor_with_threshold(record_value, state_value, threshold_days) -> bool: | ||
""" | ||
Checks if the record's cursor value is older or equal to the state cursor value. | ||
|
||
If the threshold_days option is set, the values will be converted to dates so that the time-based offset can be applied. | ||
:raises dateutil.parser._parser.ParserError: if threshold_days is passed with non-date cursor values. | ||
""" | ||
if threshold_days: | ||
record_date_value = record_value if isinstance(record_value, datetime) else dateutil.parser.parse(record_value) | ||
state_date_value = state_value if isinstance(state_value, datetime) else dateutil.parser.parse(state_value) | ||
|
||
return record_date_value >= (state_date_value - timedelta(days=threshold_days)) | ||
|
||
return record_value >= state_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only considering the threshold_days
option to be valid for date-based cursors. An offset may be desired for other types of cursors (maybe ints?), but I couldn't think of a good use case and it would make the parsing and comparison more difficult.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me! But have you tested on different connectors that send dates in different formats or just a plain integers for epoch time? Off the top of my head, I believe Hubspot sends some of their times as integers so probably worth confirming that dateutil.parse() still works with that as well.
...e-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_incremental.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Main open comment is around using Pendulum for datetime ops, I'm not super bent on it so consider it an optional request for change.
Do we have issues already for implementing this in the connectors that needed it? (if not, we should make them)
...e-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_incremental.py
Outdated
Show resolved
Hide resolved
...e-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_incremental.py
Outdated
Show resolved
Hide resolved
@brianjlai Good call-out! Hubspot itself does some converting to return ISO strings, but there are some other connectors that do return unix timestamps. Added support for that in 9cf16cc
@Phlair From what I've seen the only connectors affected are google ads (#12668) and google analytics (#12662), which do have issues created. |
/test connector=bases/source-acceptance-test
|
/publish connector=bases/source-acceptance-test
|
* SAT: add `threshold_days` incremental test option * fix: support cursor values that are already dates * dont use constant value * update docs * use pendulum for date parsing * bump cdk version * use pendulum for duration * add support for unix timestamps * bump version, update changelog
What
Support running incremental source acceptance tests for sources that use a lookback window to include records older than the requested state cursor.
close #12467
How
threshold_days
option for incremental tests to control the amount of days to allow before the state cursordateutil.parser.parse
, aParserError
will be raised.This has been confirmed to allow enabling the incremental tests for the Google Analytics connector.
Recommended reading order
source_acceptance_test/config.py
source_acceptance_test/test_incremental.py
unit_tests/test_incremental.py
Tests
Unit