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

Chore: Add docs for callback, add type alias #447

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented Nov 8, 2024

Adds a new docs page for the config callback feature, and a new type alias for readability.

Pairs with:

Summary by CodeRabbit

  • New Features

    • Introduced a callback mechanism for handling configuration changes in connectors.
    • Added a new ConfigChangeCallback type for enhanced type safety.
  • Bug Fixes

    • Improved error handling in the get_configured_catalog method to raise errors for invalid stream arguments.
  • Deprecations

    • Marked the set_streams and get_connector methods as deprecated, recommending the use of select_streams and get_source instead.
  • Documentation

    • Updated docstrings to reflect new parameter types and provide clearer guidance for users.

Copy link

vercel bot commented Nov 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
pyairbyte-api-docs ❌ Failed (Inspect) Nov 8, 2024 11:33pm

Copy link

coderabbitai bot commented Nov 8, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces a new callbacks module to the Airbyte codebase, enhancing the handling of configuration changes through a defined ConfigChangeCallback. The type of the config_change_callback parameter across various classes and functions has been updated to this new specific type, improving type safety and clarity. Additionally, some methods have been deprecated, and the overall structure of the affected classes and functions remains intact, with no significant changes to existing logic or functionality.

Changes

File Change Summary
airbyte/init.py Added import for callbacks and updated __all__ to include callbacks.
airbyte/_connector_base.py Updated config_change_callback type in ConnectorBase.__init__ from generic to ConfigChangeCallback. Removed unused import.
airbyte/callbacks.py Introduced new file defining ConfigChangeCallback for handling configuration changes.
airbyte/destinations/base.py Updated config_change_callback type in Destination.__init__ to ConfigChangeCallback. Updated imports accordingly.
airbyte/destinations/util.py Updated config_change_callback type in get_destination function to ConfigChangeCallback. Updated imports.
airbyte/sources/base.py Updated config_change_callback type in Source.__init__ to ConfigChangeCallback. Deprecated set_streams method. Clarified get_configured_catalog handling.
airbyte/sources/util.py Updated config_change_callback type in get_source function to ConfigChangeCallback. Deprecated get_connector function.

Possibly related PRs

Wanna explore any of these changes further or discuss potential implications? wdyt?


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 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 or @coderabbitai title 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

@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

🧹 Outside diff range and nitpick comments (6)
airbyte/callbacks.py (2)

10-10: Consider using TypedDict for better type safety?

The current type alias works well, but we could make it even more type-safe. What do you think about defining a ConfigDict TypedDict to specify the expected structure of the configuration dictionary? This would provide better type hints for callback implementations. wdyt?

from typing import TypedDict

class ConfigDict(TypedDict):
    # Add expected config keys here
    pass

ConfigChangeCallback = Callable[[ConfigDict], None]

11-50: Excellent documentation! Maybe add error handling to the example?

The documentation is comprehensive and well-structured! 🌟 The example is particularly helpful. Would you consider adding error handling to make it even more production-ready? Something like:

def config_callback(new_config: dict[str, Any]) -> None:
    try:
        config_file.write_text(yaml.safe_dump(new_config))
    except (IOError, yaml.YAMLError) as e:
        logger.error(f"Failed to save updated config: {e}")
        # Consider whether to re-raise or handle differently

Also, should we mention that the callback might be called from a different thread? wdyt?

airbyte/destinations/util.py (1)

25-25: The type update looks great! Quick question about the docs though...

The parameter type update to ConfigChangeCallback improves type safety nicely. Would you consider enhancing the docstring for config_change_callback to describe its expected signature? Something like "callback function (ConfigChangeCallback) that takes a config dict and returns None" perhaps? wdyt? 🤔

airbyte/sources/util.py (1)

51-51: The type annotation looks great! Maybe we could enhance the docstring a bit?

The ConfigChangeCallback parameter is well-typed. Would you like to add a bit more detail to the docstring about what kind of changes trigger the callback and maybe add an example? wdyt?

airbyte/sources/base.py (2)

63-64: Consider enhancing parameter documentation?

The new parameters could benefit from docstring updates. What do you think about adding:

  • config_change_callback: Description of when and how the callback is invoked
  • streams: Description of the expected format and behavior when using string vs list[str]

Line range hint 447-452: Consider enhancing error handling for streams argument?

The error message could be more helpful by including the actual expected types. What do you think about:

-            raise exc.PyAirbyteInputError(
-                message="Invalid streams argument.",
-                input_value=streams,
-            )
+            raise exc.PyAirbyteInputError(
+                message="Invalid streams argument. Expected '*' or list[str].",
+                input_value=streams,
+                expected_types=["'*'", "list[str]"],
+            )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6246e6b and fef4b56.

📒 Files selected for processing (7)
  • airbyte/__init__.py (2 hunks)
  • airbyte/_connector_base.py (2 hunks)
  • airbyte/callbacks.py (1 hunks)
  • airbyte/destinations/base.py (2 hunks)
  • airbyte/destinations/util.py (1 hunks)
  • airbyte/sources/base.py (2 hunks)
  • airbyte/sources/util.py (2 hunks)
🔇 Additional comments (13)
airbyte/callbacks.py (2)

1-7: Clean and well-structured module setup!

The imports are minimal and specific, and the module structure follows best practices. Nice work! 🎉


10-50: Verify thread safety requirements

Let's check if the callback might be called from different threads to ensure we provide appropriate guidance in the documentation.

airbyte/destinations/util.py (2)

18-18: Nice type safety improvement! 👍

The addition of ConfigChangeCallback import and its placement within the TYPE_CHECKING block looks great. This aligns well with the type safety improvements across the codebase.


25-25: Quick verification of consistent usage?

Let's make sure this type update is consistent across the codebase:

✅ Verification successful

Type usage appears consistent across the codebase

The ConfigChangeCallback type is used consistently in all relevant locations:

  • _connector_base.py
  • sources/base.py
  • sources/util.py
  • destinations/base.py
  • destinations/util.py

No instances of the old Callable[[dict[str, Any]], None] type were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining Callable[[dict[str, Any]], None] type annotations
# that should be using ConfigChangeCallback instead

# Search for potential callback parameter definitions
rg "config_change_callback.*:.*Callable\[\[dict\[str, Any\]\], None\]"

# Search for ConfigChangeCallback usage to confirm consistent adoption
rg "config_change_callback.*:.*ConfigChangeCallback"

Length of output: 592

airbyte/sources/util.py (2)

18-18: LGTM! Clean type import addition.

Nice job putting the ConfigChangeCallback import within the TYPE_CHECKING block! This keeps the runtime imports clean. 👍


Line range hint 21-40: The deprecation path looks good! Shall we verify the migration docs?

The deprecation warning is clear and helpful. Would you like me to check if this deprecation is documented in the changelog or migration guide?

airbyte/__init__.py (1)

128-128: LGTM! Clean addition of the callbacks module.

The changes look good - the new callbacks module is properly integrated into both the imports and __all__ list, maintaining alphabetical order and following the existing code style. This aligns well with the PR's objective of improving type safety through the new callback functionality.

Let's verify the callbacks module structure:

Also applies to: 161-161

✅ Verification successful

Looks great! The callbacks module is properly integrated and well-used across the codebase

The verification shows that:

  • The callbacks.py module exists and defines ConfigChangeCallback type
  • It's properly imported and used in key components:
    • Base connector classes
    • Source and destination utilities
    • Integration tests validate the callback functionality
  • The implementation follows a clean type-safe pattern with proper documentation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the callbacks module structure and its public interface

# Test: Check if the callbacks module exists and contains expected type definitions
rg -A 5 "ConfigChangeCallback" --type python

Length of output: 75


Script:

#!/bin/bash
# Let's try a different approach to verify the callbacks module

# Check if callbacks module exists and its content
fd "callbacks.py" --type f

# Look for any files containing "callback" in their name
fd "callback" --type f

# Search for callback-related code using ripgrep
rg -g "!node_modules" -g "!.git" "ConfigChangeCallback"

# Check the content of any Python files in the airbyte directory
fd ".py$" --type f --exec cat {} \; | rg -A 5 "callback"

Length of output: 8729

airbyte/destinations/base.py (2)

38-38: LGTM! Nice type safety improvement.

The addition of ConfigChangeCallback import in the TYPE_CHECKING block is clean and follows best practices. This aligns well with the PR's goal of improving type hints.


53-53: Type alias change looks good! Quick verification needed.

The change from Callable[[dict[str, Any]], None] | None to ConfigChangeCallback | None improves readability. Would you mind if we verify that all callers are compatible with this change? 🤔

✅ Verification successful

Let me check the type definition of ConfigChangeCallback to ensure complete verification.


All good! The type change is perfectly compatible 👍

I found that ConfigChangeCallback is defined in airbyte/callbacks.py as Callable[[dict[str, Any]], None], which is exactly the same type as before. The change is purely for better readability and all imports/usages are consistent across the codebase. Nice refactoring!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any direct instantiations of Destination class to verify compatibility
rg -A 2 "Destination\(" 

# Search for any references to config_change_callback to ensure type consistency
rg "config_change_callback.*?:" 

Length of output: 1721


Script:

#!/bin/bash
# Search for ConfigChangeCallback type definition
rg "ConfigChangeCallback.*?=" -A 2

# Also check for any imports of this type
rg "from.*?import.*?ConfigChangeCallback"

Length of output: 1743

airbyte/_connector_base.py (2)

39-39: LGTM! Clean import changes.

The removal of unused Callable import and addition of ConfigChangeCallback improves code organization.

Also applies to: 44-44


61-61: LGTM! Type annotation improvement.

The switch to ConfigChangeCallback type alias enhances code readability and type safety. The implementation correctly preserves the callback functionality in both the constructor and message processing logic.

airbyte/sources/base.py (2)

46-46: LGTM! Clean import addition.

The addition of ConfigChangeCallback import aligns well with the type safety improvements mentioned in the PR objectives.


Line range hint 89-97: LGTM! Well-implemented deprecation.

The deprecation warning is clear and helpful, providing users with the correct migration path to select_streams.

@aaronsteers aaronsteers marked this pull request as ready for review November 8, 2024 23:33
@aaronsteers aaronsteers enabled auto-merge (squash) November 8, 2024 23:34
Copy link

@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

🧹 Outside diff range and nitpick comments (2)
airbyte/callbacks.py (2)

10-10: Consider adding runtime type checking?

The type alias looks great! For enhanced developer experience, what do you think about adding runtime type checking using typing.runtime_checkable and Protocol? This would provide better error messages during development. wdyt?

from typing import Protocol, runtime_checkable

@runtime_checkable
class ConfigChangeCallback(Protocol):
    def __call__(self, config: dict[str, Any]) -> None: ...

11-50: Great docs! A couple of suggestions to make them even better

The documentation is comprehensive and well-structured! 👏 Would you consider these enhancements?

  1. The example could be more realistic by showing an OAuth refresh token scenario since it's mentioned as the most common use case. Maybe something like:
def config_callback(new_config: dict[str, Any]) -> None:
    # Store the new refresh token securely
    keyring.set_password(
        "my-oauth-service",
        "refresh_token",
        new_config["credentials"]["refresh_token"]
    )
  1. Consider adding a security note about handling sensitive config data, especially for OAuth tokens? Something like:
    "Note: When implementing the callback, ensure sensitive configuration data is stored securely."

wdyt?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fef4b56 and 2be875a.

📒 Files selected for processing (1)
  • airbyte/callbacks.py (1 hunks)
🔇 Additional comments (1)
airbyte/callbacks.py (1)

1-7: Clean and well-organized module structure!

The imports are minimal and well-organized, and I appreciate the use of __future__ import for forward compatibility.

@aaronsteers aaronsteers merged commit 8556629 into main Nov 8, 2024
19 of 20 checks passed
@aaronsteers aaronsteers deleted the aj/chore/add-callback-docs-and-type-alias branch November 8, 2024 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant