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

fix(airbyte-cdk): unable to create custom retriever #198

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

aldogonzalez8
Copy link
Contributor

@aldogonzalez8 aldogonzalez8 commented Jan 6, 2025

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced method signatures in the ModelToComponentFactory to provide more flexible parameter handling.
    • Added support for custom retriever components in the declarative stream framework.
  • Improvements

    • Made the decoder parameter optional with a default value in create_http_requester.
    • Made the transformations parameter optional in create_record_selector.

What?

I was encountering errors like the following when creating a Custom Retriever:

ValueError: Error creating component 'RecordSelector' with parent custom component source_google_sheets.components.SheetsDataRetriever: Please provide RecordSelector.$parameters.transformations

From what I can see, decoder can be optional here can is default to JsonDecoder here.

For transformations also we set it as optional here.

@aldogonzalez8 aldogonzalez8 self-assigned this Jan 6, 2025
@aldogonzalez8 aldogonzalez8 changed the title bug(airbyte-cdk): unable to create custom retriever fix(airbyte-cdk): unable to create custom retriever Jan 6, 2025
Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the ModelToComponentFactory class in the Airbyte CDK, focusing on enhancing method flexibility. The changes primarily involve adjusting method signatures for create_http_requester and create_record_selector to make certain parameters optional. This allows for more relaxed method invocation by providing default values and making some arguments optional, which simplifies the usage of these methods in declarative source configurations.

Changes

File Change Summary
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py - Modified create_http_requester to make decoder optional with a default of JsonDecoder(parameters={}).
- Updated create_record_selector to make transformations, decoder, and client_side_incremental_sync optional with defaults of None.
unit_tests/sources/declarative/parsers/test_model_to_component_factory.py - Added MyCustomRetriever class extending SimpleRetriever.
- Introduced test_create_custom_retriever test function to validate custom retriever creation.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • maxi297

Wdyt about the related PRs? Do you think they could provide additional context for your changes?


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c139f0 and 744132b.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-the-guardian-api' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Analyze (python)
  • GitHub Check: Pytest (Fast)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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

🧹 Nitpick comments (2)
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (1)

1899-1899: Double-check optional transformations parameter.

Making transformations optional simplifies usage. Nice addition! Would you consider adding a docstring clarifying the default empty list? wdyt?

🧰 Tools
🪛 GitHub Actions: Linters

[warning] File needs formatting using Ruff formatter

unit_tests/sources/declarative/parsers/test_model_to_component_factory.py (1)

2631-2633: Add a docstring or comment for the custom retriever?

Your MyCustomRetriever class inherits SimpleRetriever but has no docstring. Would you add a quick description for clarity? wdyt?

🧰 Tools
🪛 GitHub Actions: Linters

[warning] File needs formatting using Ruff formatter

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8cb659 and 100ce81.

📒 Files selected for processing (2)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (3 hunks)
  • unit_tests/sources/declarative/parsers/test_model_to_component_factory.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linters
unit_tests/sources/declarative/parsers/test_model_to_component_factory.py

[warning] File needs formatting using Ruff formatter

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

[warning] File needs formatting using Ruff formatter

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-the-guardian-api' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (Fast)
🔇 Additional comments (3)
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (2)

1515-1515: Consider verifying default decoder usage.

Setting decoder=JsonDecoder(parameters={}) as the default is handy. However, if a user wants no decoding, do you plan to support passing None or a different decoder? wdyt?

🧰 Tools
🪛 GitHub Actions: Linters

[warning] File needs formatting using Ruff formatter


1931-1931: Good fallback to empty list for transformations.

This effectively prevents errors from passing None. Looks great to me!

🧰 Tools
🪛 GitHub Actions: Linters

[warning] File needs formatting using Ruff formatter

unit_tests/sources/declarative/parsers/test_model_to_component_factory.py (1)

2635-2665: Solid test for custom retriever creation.

This covers instantiating a custom retriever in a DeclarativeStream. Everything looks in order. Great job!

🧰 Tools
🪛 GitHub Actions: Linters

[warning] File needs formatting using Ruff formatter

@aldogonzalez8
Copy link
Contributor Author

/format-fix

@github-actions github-actions bot added the bug Something isn't working label Jan 6, 2025
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

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

2637-2639: Consider adding a docstring or comment to describe the purpose of this subclass.
Even though it's a simple subclass, it might help future developers if you provide a quick explanation of this custom retriever. wdyt?


2641-2671: Add an explicit assertion to ensure MyCustomRetriever is properly tested.
Would you consider adding a small test that verifies any overridden methods or states if added in the future? For example, by checking the retriever’s internal attributes or behavior? wdyt?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 100ce81 and c18f0d7.

📒 Files selected for processing (2)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py (3 hunks)
  • unit_tests/sources/declarative/parsers/test_model_to_component_factory.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Check: 'source-the-guardian-api' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)

Copy link
Contributor

@natikgadzhi natikgadzhi left a comment

Choose a reason for hiding this comment

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

If all other tests are green, I want to unblock this! Asked a bunch of non-blocking questions, but they are, again, non-blocking.

self,
model: HttpRequesterModel,
config: Config,
decoder: Decoder = JsonDecoder(parameters={}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Help me with my shitty Python knowledge. The signature change does two things here:

  1. Add default value for decoder — this is additive and will fix situations where decoder was not passed in
  2. The order of named arguments changed. Is this important, or did we always pass them named and it's compatible?

Copy link
Contributor

Choose a reason for hiding this comment

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

The order of named arguments changed. Is this important, or did we always pass them named and it's compatible?

This is important but we assume model_to_component_factory is quite mostly private to the CDK hence I'm fine with this breaking change

decoder: Optional[Decoder] = None,
client_side_incremental_sync: Optional[Dict[str, Any]] = None,
transformations: List[RecordTransformation] | None = None,
decoder: Decoder | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Intentional that it defaults to None here, but JSONDecoder upstairs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting point. Default To None seems to work fine in a quick test, so maybe JsonDecoder(parameters={}) is unnecessary. Let me dig in a little bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, now I remember. The HttpRequester expects a decoder.

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py:1619: error: Argument "decoder" to "HttpRequester" has incompatible type "Decoder | None"; expected "Decoder" [arg-type]

But we could create one if None for consistency with the arguments I other methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a second thought, it would be a little bit redundant, so I think I will put it back as it was so:

Intentional that it defaults to None here, but JSONDecoder upstairs?

Yes, The HttpRequester expects a decoder and mypy yells for that.

@@ -2008,7 +2013,7 @@ def create_record_selector(
name=name,
config=config,
record_filter=record_filter,
transformations=transformations,
transformations=transformations or [],
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking: Is it intentional that transformations default to None on argument list of the method, but to [] here? Should we just say transormations: List[RecordTransformation] = [] in the args list, or is it parsed to None explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lint was very annoyed about using a mutable object as the default, and I thought it was safer to pass [] as the default factory does here for RecordSelector.

Copy link
Contributor

@maxi297 maxi297 left a comment

Choose a reason for hiding this comment

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

source-linkedinads has a custom retriever. Was it broken? Is there anything to do with this one?

self,
model: HttpRequesterModel,
config: Config,
decoder: Decoder = JsonDecoder(parameters={}),
Copy link
Contributor

Choose a reason for hiding this comment

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

The order of named arguments changed. Is this important, or did we always pass them named and it's compatible?

This is important but we assume model_to_component_factory is quite mostly private to the CDK hence I'm fine with this breaking change

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.

3 participants