fix: Handle FinalStateCursor gracefully and detect final-state for retention check#910
Closed
Conversation
…tention check - In _is_cursor_older_than_retention_period, continue to next cursor on NotImplementedError instead of raising SystemError. This allows the incremental cursor to be tried when the full_refresh cursor (e.g. FinalStateCursor) does not implement get_cursor_datetime_from_state. - In create_state_delegating_stream, detect final state (NO_CURSOR_STATE_KEY) and skip retention check entirely, returning incremental stream. When full_refresh completed without incremental_sync, the produced final state means we should always transition to incremental. - Add test for final-state scenario with api_retention_period. Co-Authored-By: alfredo.garcia@airbyte.io <freddy.garcia7.fg@gmail.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. 💡 Show Tips and TricksTesting This CDK VersionYou can test this version of the CDK using the following: # Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@devin/1771458776-fix-retention-period-final-state-cursor#egg=airbyte-python-cdk[dev]' --help
# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch devin/1771458776-fix-retention-period-final-state-cursorPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
Co-Authored-By: alfredo.garcia@airbyte.io <freddy.garcia7.fg@gmail.com>
Co-Authored-By: alfredo.garcia@airbyte.io <freddy.garcia7.fg@gmail.com>
Co-Authored-By: alfredo.garcia@airbyte.io <freddy.garcia7.fg@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR targets the following PR:
fix: Handle FinalStateCursor in retention check and detect final-state
Summary
Fixes two blockers in the
StateDelegatingStreamcursor age validation feature (PR #890):1. FinalStateCursor crash in
_is_cursor_older_than_retention_periodWhen iterating cursors
[full_refresh.cursor, incremental.cursor], if the full_refresh cursor is aFinalStateCursor(noincremental_syncdefined), it raisesNotImplementedErrorfrom the baseCursor.get_cursor_datetime_from_state. Previously this was caught and re-raised asSystemError, preventing the incremental cursor from ever being tried. Now the loopcontinues to the next cursor instead.2. Final-state detection in
create_state_delegating_streamWhen a full_refresh_stream without
incremental_synccompletes, it produces a "final state" ({NO_CURSOR_STATE_KEY: True}). The code now detects this sentinel state and skips the retention check entirely, returning the incremental stream directly. A completed full refresh means incremental is always correct.Review & Testing Checklist for Human
continuepath in_is_cursor_older_than_retention_periodis not directly tested. The new test only exercises the early-return final-state detection (fix 2). There is no test that creates a stream where the full_refresh cursor is an actualFinalStateCursorthat raisesNotImplementedErrorand verifies the loop falls through to the incremental cursor. Consider whether this gap needs coverage.continuechange, if every cursor in the list lacksget_cursor_datetime_from_stateor raisesNotImplementedError,cursor_datetimestaysNoneand the method returnsTrue(full refresh). Previously this was a hardSystemError. Verify this silent degradation is acceptable vs. raising an error.stream_state.get(NO_CURSOR_STATE_KEY)) rather thanis True. The actualFinalStateCursorsets the value toTrue, so this works in practice. Confirm this is sufficient.StateDelegatingStreamwhere full_refresh_stream has noincremental_sync, run a full refresh to completion (producing final state), then trigger a second sync withapi_retention_periodset — verify it transitions to incremental without crashing.Notes