Andy Chen
04/08/2022, 2:05 PME dagster.core.errors.DagsterInvalidPropertyError: The solid property is not set on the context when a solid is directly invoked.
claire
04/08/2022, 5:07 PMAndy Chen
04/08/2022, 5:09 PMclaire
04/08/2022, 5:15 PMbuild_op_context
you could build_op_context().bind(op_def)
. This would pass the op definition to the constructed context and then you could access the op name.Andy Chen
04/08/2022, 5:16 PMclaire
04/08/2022, 5:19 PMcontext.solid.name
dagster will return the aliased name of the op ("op_a_1").execute_in_process
? This would allow you to get the op name through the context object.Andy Chen
04/08/2022, 5:56 PMclaire
04/08/2022, 5:59 PMbuild_op_context
will simply have the name that it is defined with.@op
def my_op(context):
print(context.solid_def.name)
return 1
with build_op_context() as context:
my_op(context)
print(my_op.name)
Andy Chen
04/08/2022, 6:19 PME dagster.core.errors.DagsterInvalidPropertyError: The solid property is not set on the context when a solid is directly invoked.
def test_my_test_op()
context = build_op_context()
op_result = my_test_op(context)
@op
def my_test_op(context):
<http://context.log.info|context.log.info>(context.solid.name)
claire
04/08/2022, 6:36 PM<http://context.log.info|context.log.info>(context.solid_def.name
instead of context.solid.name
Andy Chen
04/08/2022, 7:35 PMclaire
04/08/2022, 7:40 PMop_2
. I think if you want to test, you could try writing unit tests that run the job through my_job.execute_in_process()
and then you'll be able to access the aliased name (op_a_2
).Andy Chen
04/08/2022, 7:41 PMclaire
04/08/2022, 7:42 PMsolid_def.name
will always return op_a
. But if you run the job an op that contains context.solid.name
you'll get the aliased nameAndy Chen
04/08/2022, 7:43 PMclaire
04/08/2022, 7:45 PMexecute_in_process
? Then you'll be able to access the aliased nameAndy Chen
04/08/2022, 7:46 PMclaire
04/08/2022, 7:48 PMmy_job.execute_in_process(op_selection=["my_op"])
Andy Chen
04/08/2022, 7:48 PMclaire
04/08/2022, 8:11 PM@op
def my_test_op(context):
<http://context.log.info|context.log.info>(f'{context.solid.name}.{context.run_id}')
Unfortunately that still doesn't solve the testability problem where context.solid.name
is not available in the test context. We do have an issue tracking this though:
https://github.com/dagster-io/dagster/issues/6493Andy Chen
04/08/2022, 8:18 PM(f'{context.solid.name}.{context.run_id}')
claire
04/08/2022, 8:34 PM@op
def my_op(context):
print(context.run_id + "." + context.get_step_execution_context().step.key)
which will get you the key within a graph (e.g. <http://my_graph.my|my_graph.my>_op
).Andy Chen
04/08/2022, 8:41 PM