Vinnie
08/08/2022, 4:58 PMassets
and ops
needing contexts . My first op in the asset takes in a context argument and when I click on Materialize on the dagit interface, dagster throws an error saying the op takes a context argument but none was provided.
The asset is loaded with the with_resources()
function, the context in the op needs to access is a resource. The problem goes away if I first define a graph and load the asset with AssetsDefinition.from_graph()
claire
08/08/2022, 10:23 PMVinnie
08/09/2022, 6:19 AMclass
that should contain the fetch()
method, but the lacking context doesn’t even get us that far so it shouldn’t be much of an issue.
@op(required_resource_keys={"baz"})
def bar(context):
return context.resources.baz.fetch()
@asset
def foo():
return bar()
@repository
def repo():
return [
*with_resources(
definitions=[foo],
resource_defs={"baz": baz},
resource_config_by_key={"baz": {"config": {"qux": "quux"}}}
)
]
And since I typed it out form memory yesterday, the exact error/stacktrace is the following:
dagster._core.errors.DagsterInvalidInvocationError: Compute function of op 'bar' has context argument, but no context was provided when invoking.
File "/Users/vinicius/Development/dagster-utils/.venv/lib/python3.9/site-packages/dagster/_core/execution/plan/execute_plan.py", line 224, in dagster_event_sequence_for_step
for step_event in check.generator(step_events):
File "/Users/vinicius/Development/dagster-utils/.venv/lib/python3.9/site-packages/dagster/_core/execution/plan/execute_step.py", line 357, in core_dagster_event_sequence_for_step
for user_event in check.generator(
File "/Users/vinicius/Development/dagster-utils/.venv/lib/python3.9/site-packages/dagster/_core/execution/plan/execute_step.py", line 69, in _step_output_error_checked_user_event_sequence
for user_event in user_event_sequence:
File "/Users/vinicius/Development/dagster-utils/.venv/lib/python3.9/site-packages/dagster/_core/execution/plan/compute.py", line 174, in execute_core_compute
for step_output in _yield_compute_results(step_context, inputs, compute_fn):
File "/Users/vinicius/Development/dagster-utils/.venv/lib/python3.9/site-packages/dagster/_core/execution/plan/compute.py", line 142, in _yield_compute_results
for event in iterate_with_context(
File "/Users/vinicius/Development/dagster-utils/.venv/lib/python3.9/site-packages/dagster/_utils/__init__.py", line 413, in iterate_with_context
next_output = next(iterator)
File "/Users/vinicius/Development/dagster-utils/.venv/lib/python3.9/site-packages/dagster/_core/execution/plan/compute_generator.py", line 73, in _coerce_solid_compute_fn_to_iterator
result = fn(context, **kwargs) if context_arg_provided else fn(**kwargs)
File "/Users/vinicius/Development/dagster-utils/dagster_utils/testable_repo.py", line 27, in foo
return bar(context)
File "/Users/vinicius/Development/dagster-utils/.venv/lib/python3.9/site-packages/dagster/_core/definitions/solid_definition.py", line 179, in __call__
raise DagsterInvalidInvocationError(
claire
08/09/2022, 5:11 PM@asset
, you could do something like this:
bar_asset = AssetsDefinition.from_op(bar)
@repository
def repo():
return [
*with_resources(
definitions=[bar_asset],
resource_defs={"baz": baz},
resource_config_by_key={"baz": {"config": {"qux": "quux"}}},
)
]
Dagster Bot
08/09/2022, 5:13 PMVinnie
08/09/2022, 5:41 PMclaire
08/09/2022, 5:45 PMAssetsDefinition.from_graph
.Vinnie
08/09/2022, 6:06 PM