Skip to content

fix(async-retriever): fix calling transformations twice #576

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

Merged
merged 4 commits into from
Jun 4, 2025

Conversation

aldogonzalez8
Copy link
Contributor

@aldogonzalez8 aldogonzalez8 commented Jun 3, 2025

What

The async retriever is calling the record transformations twice. Additionally, it appears that the record_selector is duplicated, with one instance not including the record_filter, and then it performs transformations on unfiltered data, which is undesirable.

Yes, but why?

Async retriever requires a download retriever that under the hood is a SimpleRetriever with a record_selector, to this record_selector we pass transformations, but not schema normalization, nor filters.

Async retriever also holds a record_selector with transformations, schema normalization, and filters (all of those if applied in the manifest definition).

Then both record_selectors try to filter_and_transform, causing transformations to apply twice, but with no filters for the record_selector in the download retriever (simple retriever).

What can we do?

If we don't provide schema normalization or filters, then we don't need to apply transformations to this other record_selector unless I'm missing something obvious.

Resolves https://github.com/airbytehq/airbyte-internal-issues/issues/13200

Summary by CodeRabbit

  • Bug Fixes
    • Improved data retrieval reliability by ensuring that certain data transformations and filters are correctly applied during asynchronous data fetching.
    • Enhanced data processing accuracy by isolating transformations and filters to specific retrieval steps, preventing unintended data modifications.
    • Increased test robustness by making stream and record order irrelevant in validation checks.

@aldogonzalez8 aldogonzalez8 self-assigned this Jun 3, 2025
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

📝 Walkthrough

Walkthrough

The create_async_retriever method in the model-to-component factory was updated to construct the download retriever's record_selector with no transformations, no record filter, and a no-op schema normalization. These responsibilities are now clarified as being handled by the AsyncRetriever's own record selector.

Changes

File(s) Change Summary
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py Modified create_async_retriever to set download retriever's record_selector with empty transformations, no record filter, and a no-op schema normalization. Added clarifying comment.
unit_tests/sources/declarative/parsers/test_model_to_component_factory.py Updated test_create_async_retriever to include a transformation in the async retriever and assert that these transformations do not propagate to the download retriever's record selector.
unit_tests/sources/declarative/resolvers/test_config_components_resolver.py Changed stream name assertions from list equality to set equality to remove order dependency in tests.

Sequence Diagram(s)

sequenceDiagram
    participant Factory as ModelToComponentFactory
    participant DownloadRetriever
    participant AsyncRetriever

    Factory->>DownloadRetriever: Construct with record_selector (no transformations, no filter, no schema normalization)
    Factory->>AsyncRetriever: Construct with its own record_selector (handles transformations, filter, normalization)
Loading

Would you like a more detailed breakdown of how the record selector responsibilities are split between the download retriever and the async retriever, wdyt?

Possibly related PRs

Suggested labels

area/async-retriever

Suggested reviewers

  • brianjlai
  • artem1205

📜 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 e9f378e and c107e87.

📒 Files selected for processing (1)
  • unit_tests/sources/declarative/resolvers/test_config_components_resolver.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Check: 'source-amplitude' (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 (2)
unit_tests/sources/declarative/resolvers/test_config_components_resolver.py (2)

206-207: Good improvement to make the test more robust!

Using set comparison instead of list comparison removes the dependency on deterministic ordering while still ensuring correctness. The explanatory comment makes the intent clear. This aligns well with the async retriever fixes where ordering might become non-deterministic, wdyt?


209-210: Consistent approach for record stream validation!

Same excellent pattern applied here - using set comparison for record stream names maintains test reliability without relying on order. The matching comment style keeps the code well-documented. Nice consistency with the earlier change!

✨ Finishing Touches
  • 📝 Generate Docstrings

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. Examples:
    • @coderabbitai explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@aldogonzalez8 aldogonzalez8 changed the title bug(async-retriever): fix calling transformationws twice fix(async-retriever): fix calling transformationws twice Jun 3, 2025
@github-actions github-actions bot added the bug Something isn't working label Jun 3, 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 (1)
unit_tests/sources/declarative/parsers/test_model_to_component_factory.py (1)

3883-3892: Great test coverage for the transformation fix! Could we clean up a few minor issues, wdyt?

The assertions perfectly validate that:

  1. Transformations are applied to the async retriever's record_selector
  2. The download retriever's record_selector has no transformations, filters, or schema normalization

A couple of minor suggestions:

-    # Validate the transformations are just passed to the async retriever record_selector but not the download retriever record_selector
+    # Validate transformations are passed to async retriever record_selector 
+    # but not the download retriever record_selector

The line length warning is valid - could we break this comment into two lines to stay under 100 characters?

Also, accessing _config is a protected member, but this is common in unit tests for validation purposes, so it's probably fine here.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 3883-3883: Line too long (136/100)

(C0301)


[warning] 3891-3891: Access to a protected member _config of a client class

(W0212)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bbc4bf1 and 666bd76.

📒 Files selected for processing (1)
  • unit_tests/sources/declarative/parsers/test_model_to_component_factory.py (2 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
unit_tests/sources/declarative/parsers/test_model_to_component_factory.py

[convention] 3883-3883: Line too long (136/100)

(C0301)


[warning] 3891-3891: Access to a protected member _config of a client class

(W0212)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
🔇 Additional comments (2)
unit_tests/sources/declarative/parsers/test_model_to_component_factory.py (2)

3831-3845: LGTM! Clean transformation setup for testing.

The transformations definition follows the established pattern from other tests in this file and creates a simple AddFields transformation that's perfect for validating the fix.


3853-3853: Good addition to enable transformation testing.

Adding the transformations parameter allows the test to validate the fix for the double transformation issue.

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.

I see it was done as part of this PR. I see the reason for the extra_fields stuff but I don't see the reason for the transformations here. Was there a bug when Artem added this? @brianjlai do you have more context on this as the reviewer?

@aldogonzalez8
Copy link
Contributor Author

I see it was done as part of this PR. I see the reason for the extra_fields stuff but I don't see the reason for the transformations here. Was there a bug when Artem added this? @brianjlai do you have more context on this as the reviewer?

@brianjlai if it helps I see here @artem1205 was working on "identified a gap in the functionality of AsyncRetriever needed for amazon ads". Not sure if there was a track for such gap.

@brianjlai
Copy link
Contributor

The only thing I can think of was that while fixing the other bug, he noticed that we weren't passing the transformations into the selector and thought it was another oversight so he added it in. But I don't think any of us questioned it and the oversight is we all didn't consider that the AsyncRetriever was responsible for owning the selector and transformation of records.

I think we're fine to make this change

Copy link
Contributor

@brianjlai brianjlai left a comment

Choose a reason for hiding this comment

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

🛠️

@aldogonzalez8 aldogonzalez8 merged commit f03dc9f into main Jun 4, 2025
28 checks passed
@aldogonzalez8 aldogonzalez8 deleted the ac8/fix-calling-transformations-twice branch June 4, 2025 14:05
@aldogonzalez8 aldogonzalez8 changed the title fix(async-retriever): fix calling transformationws twice fix(async-retriever): fix calling transformations twice Jun 4, 2025
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.

4 participants