fix(declarative): ignore NO_CURSOR_STATE_KEY sentinel when reconstructing parent stream state#1069
Draft
devin-ai-integration[bot] wants to merge 1 commit into
Draft
Conversation
…ting parent stream state Co-Authored-By: bot_apk <apk@cognition.ai>
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/1783576693-fix-substream-no-cursor-sentinel#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/1783576693-fix-substream-no-cursor-sentinelPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
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.
Summary
Fixes a CDK crash at stream-construction time for manifest/low-code connectors that use a
SubstreamPartitionRouterwithincremental_dependency: true, where a child stream can persist the no-cursor sentinel state{"__ab_no_cursor_state_message": True}(NO_CURSOR_STATE_KEY).ModelToComponentFactory._instantiate_parent_stream_state_managerhas a fallback that reconstructs a parent stream's state from the child's state when it can't findparent_state/global_state. When the child's state dict has exactly one value, it used that value as the parent cursor value:When the child previously completed with no cursor state,
child_state == {"__ab_no_cursor_state_message": True}, so the fallback synthesized parent state{cursor_field: True}. Building the parent'sConcurrentCursorthen callsCustomFormatConcurrentStreamStateConverter.parse_timestamp(True), which no datetime format matches, raising:(preceded by the warn log
Trying to get_parent_state for stream ... when there are not parent state in the state).Fix
Exclude the
NO_CURSOR_STATE_KEYsentinel from the values considered by the reconstruction fallback:When the child's only state entry is the sentinel, no parent state is synthesized, so the parent cursor initializes from its configured
start_datetime(equivalent to a first/empty parent sync) instead of a bogus boolean low-water-mark. This mirrors the existing sentinel handling inConcurrentCursor.get_cursor_datetime_from_state(stream_state.get(NO_CURSOR_STATE_KEY)) and keeps real cursor state untouched.The fix is kept at the reconstruction site (the site that produces the bad value) rather than papering over the symptom in the state-parsing layer, and does not drop or corrupt real cursor state.
Test
Added
test_create_concurrent_cursor_from_perpartition_cursor_ignores_no_cursor_sentinel_child_stateinunit_tests/sources/declarative/parsers/test_model_to_component_factory.py:SubstreamPartitionRouter,incremental_dependency: true) whose incoming child state is{"__ab_no_cursor_state_message": True}.2024-01-01T00:00:00.000000+0000) with no parent low-water-mark applied.main(raises theValueError) and passes with this change.Also ran the existing
test_model_to_component_factory.pyandtest_concurrent_perpartitioncursor.pysuites (153 passed), plusruff check,ruff format, andmypy— all clean.Context
This CDK bug affects any manifest/low-code connector using substream partition routers with
incremental_dependencywhere a child stream can persist the no-cursor sentinel; the fix and test are scoped generally rather than to a specific connector.Triaged by Devin from oncall issue airbytehq/oncall#13077 (surfaced via source-hubspot production job 93884337). The connector manifest is correct — the defect is in the CDK.
Related to https://github.com/airbytehq/oncall/issues/13077:
Link to Devin session: https://app.devin.ai/sessions/bf3e5416bb094ff3b9d896fabea7cae0