Skip to content

Conversation

brianjlai
Copy link
Contributor

@brianjlai brianjlai commented Aug 24, 2025

We were accidentally referencing the runtime DeclarativeStream component as a parameter to the CustomStateMigration. This should have actually instead been the Pydantic model of the component as shown by the fields we're referencing in the __init__(). This is needed for when we deprecate the legacy DeclarativeStream component.

This also had the unfortunate effect of making a few of our actual connectors import the wrong component which prevents us from moving DeclarativeStream to a legacy folder.

Summary by CodeRabbit

  • Tests
    • Updated unit tests to align with the latest declarative stream model, ensuring compatibility with recent schema updates. No user-facing behavior changes.
  • Chores
    • Aligned test imports and type annotations with current SDK conventions for consistency and maintainability.

@github-actions github-actions bot added the bug Something isn't working label Aug 24, 2025
Copy link

👋 Greetings, Airbyte Team Member!

Here are some helpful tips and reminders for your convenience.

Testing This CDK Version

You 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@brian/fix_state_migration_to_use_declarative_stream_model#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 brian/fix_state_migration_to_use_declarative_stream_model

Helpful Resources

PR Slash Commands

Airbyte Maintainers can execute the following slash commands on your PR:

  • /autofix - Fixes most formatting and linting issues
  • /poetry-lock - Updates poetry.lock file
  • /test - Runs connector tests with the updated CDK
  • /poe build - Regenerate git-committed build artifacts, such as the pydantic models which are generated from the manifest JSON schema in YAML.
  • /poe <command> - Runs any poe command in the CDK environment

📝 Edit this welcome message.

Copy link
Contributor

coderabbitai bot commented Aug 24, 2025

📝 Walkthrough

Walkthrough

Replaced DeclarativeStream with DeclarativeStreamModel in unit_tests/sources/declarative/custom_state_migration.py, updating the import path and type annotations for the declarative_stream attribute and init parameter. No other logic changes are indicated.

Changes

Cohort / File(s) Summary
Type import and annotations update
unit_tests/sources/declarative/custom_state_migration.py
Switched import from airbyte_cdk.sources.declarative.declarative_stream.DeclarativeStream to airbyte_cdk.sources.declarative.models.declarative_component_schema.DeclarativeStream as DeclarativeStreamModel; updated declarative_stream attribute and __init__ parameter annotations from DeclarativeStream to DeclarativeStreamModel.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • maxi297
  • darynaishchenko
  • tolik0

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch brian/fix_state_migration_to_use_declarative_stream_model

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
unit_tests/sources/declarative/custom_state_migration.py (1)

24-26: Bug: evaluated cursor field is computed but not used in migrate(); use the resolved value, wdyt?

You compute self._cursor_field via InterpolatedString.create(...).eval(self._config) but still reference self._cursor.cursor_field (possibly a template) when reading and writing state. This can cause KeyError or incorrect keys if templating is involved.

-        updated_at = stream_state[self._cursor.cursor_field]
+        updated_at = stream_state[self._cursor_field]

         migrated_stream_state = {
             "states": [
                 {
                     "partition": {"type": "type_1"},
-                    "cursor": {self._cursor.cursor_field: updated_at},
+                    "cursor": {self._cursor_field: updated_at},
                 },
                 {
                     "partition": {"type": "type_2"},
-                    "cursor": {self._cursor.cursor_field: updated_at},
+                    "cursor": {self._cursor_field: updated_at},
                 },
             ]
         }

Also applies to: 31-45

🧹 Nitpick comments (2)
unit_tests/sources/declarative/custom_state_migration.py (2)

16-17: Remove stray class-level config annotation (or initialize an instance attribute), wdyt?

There’s a class-level config: Config annotation but only self._config is set in __init__. This can confuse readers and type checkers.

Apply this minimal cleanup:

 class CustomStateMigration(StateMigration):
     declarative_stream: DeclarativeStreamModel
-    config: Config

19-23: Minor robustness in init: type the assignment and default parameters to dict, wdyt?

Typing the instance attribute and guarding against None parameters avoids edge-case Nones from models and keeps type-checkers happy.

-    def __init__(self, declarative_stream: DeclarativeStreamModel, config: Config):
-        self._config = config
-        self.declarative_stream = declarative_stream
-        self._cursor = declarative_stream.incremental_sync
-        self._parameters = declarative_stream.parameters
+    def __init__(self, declarative_stream: DeclarativeStreamModel, config: Config):
+        self._config: Config = config
+        self.declarative_stream = declarative_stream
+        self._cursor = declarative_stream.incremental_sync
+        self._parameters = (declarative_stream.parameters or {})

Optional: consider asserting self._cursor is present for clearer failures when a non-incremental stream is passed (can be added later if needed).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2b07f93 and 26b4244.

📒 Files selected for processing (1)
  • unit_tests/sources/declarative/custom_state_migration.py (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ChristoGrab
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the `YamlDeclarativeSource` class in `airbyte_cdk/sources/declarative/yaml_declarative_source.py`, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.
📚 Learning: 2024-11-18T23:40:06.391Z
Learnt from: ChristoGrab
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the `YamlDeclarativeSource` class in `airbyte_cdk/sources/declarative/yaml_declarative_source.py`, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.

Applied to files:

  • unit_tests/sources/declarative/custom_state_migration.py
📚 Learning: 2024-11-15T01:04:21.272Z
Learnt from: aaronsteers
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/cli/source_declarative_manifest/_run.py:62-65
Timestamp: 2024-11-15T01:04:21.272Z
Learning: The files in `airbyte_cdk/cli/source_declarative_manifest/`, including `_run.py`, are imported from another repository, and changes to these files should be minimized or avoided when possible to maintain consistency.

Applied to files:

  • unit_tests/sources/declarative/custom_state_migration.py
🧬 Code graph analysis (1)
unit_tests/sources/declarative/custom_state_migration.py (1)
airbyte_cdk/sources/declarative/migrations/state_migration.py (1)
  • StateMigration (7-24)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
🔇 Additional comments (1)
unit_tests/sources/declarative/custom_state_migration.py (1)

9-11: Verified: custom_state_migration.py has no runtime DeclarativeStream imports — I ran the sweep and confirmed that this file now only uses the Pydantic model alias. All remaining DeclarativeStream imports live in other tests and source files by design. Does that match your expectation? wdyt?

Copy link

github-actions bot commented Aug 24, 2025

PyTest Results (Fast)

3 746 tests  ±0   3 734 ✅ ±0   6m 23s ⏱️ +5s
    1 suites ±0      12 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 776e0c9. ± Comparison against base commit 9a075a1.

♻️ This comment has been updated with latest results.

Copy link

PyTest Results (Full)

3 695 tests  ±0   3 684 ✅ ±0   9m 30s ⏱️ -9s
    1 suites ±0      11 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 26b4244. ± Comparison against base commit 2b07f93.

@brianjlai brianjlai merged commit 1b42145 into main Sep 13, 2025
21 checks passed
@brianjlai brianjlai deleted the brian/fix_state_migration_to_use_declarative_stream_model branch September 13, 2025 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants