You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I now want to use PartitionedAssetExecutionContext as a type hint for context I get a DagsterInvalidDefinitionError in _validate_context_type_hint.
I can set context.partition_on in my decorator without changing the type hint and the Code will not break. However, it would be nice to be able to guarantee that the context has those attributes.
Ideas of implementation
The implementation of _validate_context_type_hint could be changed so that it also accepts any subclasses of:
AssetExecutionContext,
OpExecutionContext,
AssetCheckExecutionContext
The function could probably be changed like so:
def_validate_context_type_hint(fn):
frominspectimport_emptyasEmptyAnnotationfromdagster._core.decorator_utilsimportget_function_paramsfromdagster._core.definitions.decorators.op_decoratorimportis_context_providedfromdagster._core.execution.context.computeimport (
AssetCheckExecutionContext,
AssetExecutionContext,
OpExecutionContext,
)
params=get_function_params(fn)
ifis_context_provided(params):
context_classes= [
AssetExecutionContext,
OpExecutionContext,
AssetCheckExecutionContext
]
ifnotany(
params[0].annotationiscontext_classorissubclass(params[0].annotation, context_class)
forcontext_classincontext_classes
) orparams[0].annotationisnotEmptyAnnotation:
raiseDagsterInvalidDefinitionError(
f"Cannot annotate `context` parameter with type {params[0].annotation}. `context`"" must be annotated with AssetExecutionContext, AssetCheckExecutionContext, OpExecutionContext, or left blank."
)
Additional information
No response
Message from the maintainers
Impacted by this issue? Give it a 👍! We factor engagement into prioritization.
The text was updated successfully, but these errors were encountered:
What's the use case?
I'm extending the @asset decorator with some arguments that I will also need in the asset function. I'm using context to pass these down like so:
Now I've extended AssetExecutionContext like so:
If I now want to use PartitionedAssetExecutionContext as a type hint for context I get a DagsterInvalidDefinitionError in _validate_context_type_hint.
I can set context.partition_on in my decorator without changing the type hint and the Code will not break. However, it would be nice to be able to guarantee that the context has those attributes.
Ideas of implementation
The implementation of _validate_context_type_hint could be changed so that it also accepts any subclasses of:
The function could probably be changed like so:
Additional information
No response
Message from the maintainers
Impacted by this issue? Give it a 👍! We factor engagement into prioritization.
The text was updated successfully, but these errors were encountered: