Skip to content

fix: (CDK) (AsyncRetriever) - fix availability strategy issues, during check connection #419

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

Conversation

bazarnov
Copy link
Contributor

@bazarnov bazarnov commented Mar 13, 2025

What

Original Slack conversation: https://airbytehq-team.slack.com/archives/C07JMAAE620/p1741825218622419

Problem Statement:

  • Attempting to utilize the name of an asynchronous stream in CheckStream resulted in an error during the check request process when attempting to establish a Source for that manifest.
  • The issue is associated with the availability strategy that searches for the retriever.requester.exit_on_rate_limits, which is not available for the AsyncRetriever.

How

  • created dedicated property methods to expose the creation_requester.exit_on_rate_limits and re-use it

User Impact

With this update, customers who utilize the AsyncRetriever will now have the capability to specify the asynchronous stream as the one for checking the connection. This was not the case previously.

Summary by CodeRabbit

  • New Features

    • Introduced an asynchronous retrieval mode with enhanced rate limit handling, providing improved flexibility in managing job creation when limits are reached.
  • Documentation

    • Updated guidance and explanations around rate limit management in asynchronous operations for clearer understanding.

@bazarnov bazarnov self-assigned this Mar 13, 2025
@Copilot Copilot AI review requested due to automatic review settings March 13, 2025 14:11
@github-actions github-actions bot added bug Something isn't working security labels Mar 13, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issues with the AsyncRetriever's availability strategy during a check connection by exposing a dedicated property for handling rate limits.

  • Introduces a new property and setter for exit_on_rate_limit in AsyncRetriever.
  • Updates declarative_stream to branch its behavior based on whether the retriever is an AsyncRetriever.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
airbyte_cdk/sources/declarative/retrievers/async_retriever.py Adds new exit_on_rate_limit property and setter to support async logic.
airbyte_cdk/sources/declarative/declarative_stream.py Integrates AsyncRetriever exit_on_rate_limit in stream configuration.

Copy link
Contributor

coderabbitai bot commented Mar 13, 2025

📝 Walkthrough

Walkthrough

This pull request introduces an AsyncRetriever to the DeclarativeStream class, modifying the exit_on_rate_limit property's getter and setter to accommodate this new retriever type. The getter now retrieves the value from the AsyncRetriever if applicable, while the setter updates it accordingly. Additionally, a new exit_on_rate_limit property with its getter and setter has been added to the AsyncRetriever class, enhancing the management of job creation based on rate limits. Import statements and documentation have been updated to reflect these changes.

Changes

File(s) Change Summary
airbyte_cdk/sources/declarative/declarative_stream.py Updated the exit_on_rate_limit property's getter and setter to check if the retriever is an instance of AsyncRetriever and delegate accordingly; added an import for AsyncRetriever.
airbyte_cdk/sources/declarative/retrievers/async_retriever.py Introduced a new exit_on_rate_limit property with getter and setter; expanded documentation to clarify interactions with job creation and rate limits.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • darynaishchenko
  • aldogonzalez8

Would you like to proceed with these reviewers, wdyt?

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 b3da6d3 and 8e0881f.

📒 Files selected for processing (1)
  • airbyte_cdk/sources/declarative/retrievers/async_retriever.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • 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: SDM Docker Image Build
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
airbyte_cdk/sources/declarative/retrievers/async_retriever.py (2)

39-56: Implementation looks good with proper null checking.

This getter implementation properly handles the case when job_orchestrator is None, which addresses the type checking issues mentioned in previous reviews. The documentation clearly explains the purpose and behavior of this property.

The type ignore comment at line 56 is a bit generic though. Could we make it more specific like # type: ignore[attr-defined, return-value] to better document exactly what type issues we're suppressing, wdyt?


58-67: Setter implementation with null checking looks good.

The implementation correctly checks for a null job_orchestrator before attempting to set the property value, which prevents potential runtime errors. I see you've also fixed the typo "futher" to "further" in the docstring as suggested in previous reviews.

The explicit type ignore annotation # type: ignore[attr-defined, assignment] is good as it clearly documents what's being suppressed.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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: 2

🧹 Nitpick comments (1)
airbyte_cdk/sources/declarative/retrievers/async_retriever.py (1)

39-62: Consider using a more resilient property chain access pattern

The current implementation has a deep property access chain that's fragile to changes and causing type checking issues. Consider implementing a more resilient pattern:

@property
def exit_on_rate_limit(self) -> bool:
    """
    Whether to exit on rate limit. This is a property of the job repository
    and not the stream slicer. The stream slicer is responsible for creating
    the jobs, but the job repository is responsible for managing the rate
    limits and other job-related properties.

    Note:
     - If the `creation_requester` cannot place / create the job - it might be the case of the RateLimits
     - If the `creation_requester` can place / create the job - it means all other requesters should successfully manage
       to complete the results.
    """
-    return self.stream_slicer._job_orchestrator._job_repository.creation_requester.exit_on_rate_limit  # type: ignore[return-value]
+    # Use a helper method to safely access nested properties
+    def get_creation_requester():
+        if not hasattr(self.stream_slicer, "_job_orchestrator") or self.stream_slicer._job_orchestrator is None:
+            return None
+        job_orchestrator = self.stream_slicer._job_orchestrator
+        if not hasattr(job_orchestrator, "_job_repository") or job_orchestrator._job_repository is None:
+            return None
+        job_repository = job_orchestrator._job_repository
+        if not hasattr(job_repository, "creation_requester") or job_repository.creation_requester is None:
+            return None
+        return job_repository.creation_requester
+    
+    requester = get_creation_requester()
+    return requester.exit_on_rate_limit if requester and hasattr(requester, "exit_on_rate_limit") else False

@exit_on_rate_limit.setter
def exit_on_rate_limit(self, value: bool) -> None:
    """
    Sets the `exit_on_rate_limit` property of the job repository > creation_requester,
    meaning that the Job cannot be placed / created if the rate limit is reached.
    Thus no futher work on managing jobs is expected to be done.
    """
-    self.stream_slicer._job_orchestrator._job_repository.creation_requester.exit_on_rate_limit = value  # type: ignore[assignment]
+    # Use a helper method to safely access nested properties
+    def get_creation_requester():
+        if not hasattr(self.stream_slicer, "_job_orchestrator") or self.stream_slicer._job_orchestrator is None:
+            return None
+        job_orchestrator = self.stream_slicer._job_orchestrator
+        if not hasattr(job_orchestrator, "_job_repository") or job_orchestrator._job_repository is None:
+            return None
+        job_repository = job_orchestrator._job_repository
+        if not hasattr(job_repository, "creation_requester") or job_repository.creation_requester is None:
+            return None
+        return job_repository.creation_requester
+    
+    requester = get_creation_requester()
+    if requester and hasattr(requester, "exit_on_rate_limit"):
+        requester.exit_on_rate_limit = value

This approach:

  1. Makes the code more resilient to structural changes
  2. Handles missing attributes gracefully
  3. Improves code readability
  4. Addresses type checking issues

What do you think?

🧰 Tools
🪛 GitHub Actions: Linters

[error] 52-52: Returning Any from function declared to return 'bool' [no-any-return]


[error] 52-52: Item 'None' of 'AsyncJobOrchestrator | None' has no attribute '_job_repository' [union-attr]


[error] 52-52: Item 'AsyncJobRepository' of 'AsyncJobRepository | Any' has no attribute 'creation_requester' [union-attr]


[error] 61-61: Item 'None' of 'AsyncJobOrchestrator | None' has no attribute '_job_repository' [union-attr]


[error] 61-61: Item 'AsyncJobRepository' of 'AsyncJobRepository | Any' has no attribute 'creation_requester' [union-attr]

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b79177b and b3da6d3.

📒 Files selected for processing (2)
  • airbyte_cdk/sources/declarative/declarative_stream.py (2 hunks)
  • airbyte_cdk/sources/declarative/retrievers/async_retriever.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linters
airbyte_cdk/sources/declarative/retrievers/async_retriever.py

[error] 52-52: Returning Any from function declared to return 'bool' [no-any-return]


[error] 52-52: Item 'None' of 'AsyncJobOrchestrator | None' has no attribute '_job_repository' [union-attr]


[error] 52-52: Item 'AsyncJobRepository' of 'AsyncJobRepository | Any' has no attribute 'creation_requester' [union-attr]


[error] 61-61: Item 'None' of 'AsyncJobOrchestrator | None' has no attribute '_job_repository' [union-attr]


[error] 61-61: Item 'AsyncJobRepository' of 'AsyncJobRepository | Any' has no attribute 'creation_requester' [union-attr]

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • 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 (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Analyze (python)
🔇 Additional comments (3)
airbyte_cdk/sources/declarative/declarative_stream.py (3)

17-17: Import addition looks good

Adding the AsyncRetriever import enables the type checking that follows. Nice job keeping the imports organized alphabetically!


79-82: Good handling of different retriever types

The property now correctly handles both AsyncRetriever and standard retrievers. This is a clean way to support both retrieval mechanisms.


86-90: Clean implementation of the setter

The setter mirrors the getter logic nicely, maintaining symmetry in the codebase. The implementation correctly delegates to the appropriate object based on the retriever type.

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.

LGTM! I've started a brainstorm here to try to find a way for us to avoid to do this for every retrievers we add

@bazarnov bazarnov merged commit 9ad9e09 into main Mar 13, 2025
26 checks passed
@bazarnov bazarnov deleted the baz/cdk/fix-async-retriever-check-connection-availability-strategy branch March 13, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants