Hi everyone, Is there a way of using dicts on Out...
# ask-community
i
Hi everyone, Is there a way of using dicts on Outputs while using OPs and JOBs concept? I tried something like below but I'm getting this error: AttributeError: 'InvokedNodeOutputHandle' object has no attribute 'get' it's like it doesn't understand that it's a dict.
Copy code
@op(out={"result": Out(dict)})
def my_op():
   ... stuff
   return Output(result_dict, "result")

then on the job

@job
def my_job():
   result = my_op()
   another_op(result.get('field1'), result.get('field2'), result.get('field3'))
dagster bot responded by community 1
m
Perhaps not what you're looking for, but you could pass the entire dict to another_op() and get the required fields from there?
Copy code
@op(out={"result": Out(dict)})
def my_op():
    result_dict = {"field1": "value1", "field2": "value2", "field3": "value3"}
    return Output(result_dict, "result")


@op
def another_op(context, result_dict):
    <http://context.log.info|context.log.info>(result_dict.get("field1"))
    <http://context.log.info|context.log.info>(result_dict.get("field2"))
    <http://context.log.info|context.log.info>(result_dict.get("field3"))


@job
def my_job():
    result = my_op()
    another_op(result)
❤️ 1
i
As I'm out of options, I'll try that, thanks.
z
you can also pass the dict values as multiple outputs from
my_op
, something like
Copy code
@op(out={"result": Out(dict)})
def my_op():
   ... stuff
   yield Output(result_dict.get("field1"), "result1")
   yield Output(result_dict.get("field2"), "result2")
   yield Output(result_dict.get("field3"), "result3")

@job
def my_job():
    result1, result2, result3 = my_op()
    another_op(result1, result2, result3)
the problem you're running into is that the code within the @job job definition is only executed when your code is initially loaded by Dagster in order to compile the DAG - it isn't run when you execute the graph. this means you can't use general-purpose python code that accesses the results that are produced at runtime from within a @job or @graph definition.
❤️ 1
i
Yeah, I was hoping to avoid doing all these Outputs by just returning one Dict with everything I needed. Guess the lazy works twice, here hahaha