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: unravel Optional to inner generic arg from instance #2172

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from

Conversation

otosky
Copy link

@otosky otosky commented Dec 22, 2024

Addresses resources created by the rest_api_resources factory function exiting prematurely when trying to _join_external_scheduler and not inferring start/end dates from Airflow.

Related Issues

Closes #2171

Additional Context

Copy link

netlify bot commented Dec 22, 2024

Deploy Preview for dlt-hub-docs canceled.

Name Link
🔨 Latest commit d7793da
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/6768d7a0c4ae31000840509e

@otosky
Copy link
Author

otosky commented Dec 22, 2024

This could also potentially be moved up the call stack into IncrementalResourceWrapper.wrap, such that __orig_class__ is the actual Incremental type annotation and not wrapped in an Optional?

new_incremental.__orig_class__ = p.annotation # type: ignore

Copy link
Collaborator

@rudolfix rudolfix left a comment

Choose a reason for hiding this comment

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

thanks for the fix and writing the test! pls see the review comments

@@ -438,6 +438,10 @@ def get_generic_type_argument_from_instance(
"""
orig_param_type = Any
if cls_ := getattr(instance, "__orig_class__", None):
# unfurl Optional[Incremental[...]] to Incremental[...]
if is_optional_type(cls_):
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could also look at extract_inner_type in common/typing.py. it will unfurl other wrappers (ie. Annotated) and also nested cases

Copy link
Author

Choose a reason for hiding this comment

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

Nice! Got rid of the conditional check and just used extract_inner_type instead.


def test_get_generic_type_argument_from_instance() -> None:
# generic contains hint
instance = SimpleNamespace(__orig_class__=Incremental[str])
Copy link
Collaborator

Choose a reason for hiding this comment

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

we are trying to keep the common module as the upstream dependency of all other top level modules. so it is better to not import from extract here. You could just use any standard generic type for testing

Copy link
Author

Choose a reason for hiding this comment

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

Great point - updated in a4e5c11

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.

rest_api_resources exit early when joining external schedulers
2 participants