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

Merged
merged 7 commits into from
Jan 8, 2025

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.

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?

@aldogonzalez8
Copy link
Contributor Author

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

@maxi297 Ok, it took me a few annoying minutes of debugging but I think I found why this works fine for linkedin-ads, I can see every Custom Retriever is paried with a Custom Requester

image

So the custom retriever is not tied to a "regular" requester like HttpRequester, so they don't depend on create_httprequester but on _create_nested_component that is inside create_custom_component:

Linkedin ads:

  • Create Custom retriever LinkedInAdsCustomRetriever requires create_custom_component
    • Create Custom requester SafeEncodeHttpRequester requires create_nested_component (called inside create_custom_component) that calls create_component_from_model that calls create_custom_component (component_constructor)

image

image

image

image

On the other side, this PR tries to fix the scenario of creating a CustomRetriever with no-custom requester like HttpRequester that will use create_http_requester. Regularly I think this works fine as create_simple_retriever will create a decoder if missing.

@aldogonzalez8
Copy link
Contributor Author

@maxi297 Also doing a dummy experiment if I try to create a CustomRetriever with an HttpRequester in linkedin-ads I see the error I observed when working with google-sheets

image

            except TypeError as error:
                missing_parameters = self._extract_missing_parameters(error)
                if missing_parameters:
                    raise ValueError(
                        f"Error creating component '{type_name}' with parent custom component {model.class_name}: Please provide "
                        + ", ".join((f"{type_name}.$parameters.{parameter}" for parameter in missing_parameters))
                    )
>               raise TypeError(f"Error creating component '{type_name}' with parent custom component {model.class_name}: {error}")
E               TypeError: Error creating component 'HttpRequester' with parent custom component source_linkedin_ads.components.LinkedInAdsCustomRetriever: ModelToComponentFactory.create_http_requester() missing 1 required positional argument: 'decoder'

@aldogonzalez8 aldogonzalez8 merged commit e78eaff into main Jan 8, 2025
19 checks passed
@aldogonzalez8 aldogonzalez8 deleted the aldogonzalez8/changes-for-custom-retriever branch January 8, 2025 22:53
rpopov added a commit to rpopov/airbyte-python-cdk that referenced this pull request Jan 8, 2025
* main:
  fix(airbyte-cdk): unable to create custom retriever (airbytehq#198)
  feat(low-code): added keys replace transformation (airbytehq#183)
  feat: add `min` macros (airbytehq#203)
  fix(low-code cdk pagination): Fix the offset strategy so that it resets back to 0 when a stream is an incremental data feed (airbytehq#202)
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