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

_validate_context_type_hint assumes params[0].annotation is a class, but in fact it's a string with from __future__ import annotations #26837

Open
Colossus opened this issue Jan 4, 2025 · 0 comments
Labels
type: bug Something isn't working

Comments

@Colossus
Copy link

Colossus commented Jan 4, 2025

What's the issue?

I'm annotating my assets params with types as follows:

from __future__ import annotations

@asset(partitions_def=MY_PARTITIONS)
def my_asset(context: AssetExecutionContext) -> None:
    ...

This leads to the following exception:

dagster._core.errors.DagsterInvalidDefinitionError: Cannot annotate `context` parameter with type AssetExecutionContext. 
`context` must be annotated with AssetExecutionContext, AssetCheckExecutionContext, OpExecutionContext, or left blank.

However, the method _validate_context_type_hint in dagster/_core/definitions/op_definition.py will always fail since params[0].annotation is a str, not a class, when using from __future__ import annotations.

What did you expect to happen?

I annotated my context with the correct type parameter, AssetExecutionContext, nonetheless I'm getting this exception

How to reproduce?

Just add a param context: AssetExecutionContext and add from __future__ import annotations (more powerful type annotations) at the top of the file

Dagster version

dagster, version 1.9.5

Deployment type

Local

Deployment details

No response

Additional information

No response

Message from the maintainers

Impacted by this issue? Give it a 👍! We factor engagement into prioritization.

@Colossus Colossus added the type: bug Something isn't working label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant