https://dagster.io/ logo
Title
j

Jan Hajny

04/18/2023, 2:07 PM
Hi folks, I have an asset annotated with return value
-> None
because it is not supposed to return anything. I still want to return some metadata of its materialization. This unfortunately doesn't work:
return Output(
        None,
        metadata={
            'my_metadata': my_value,
        }
    )
What would be the correct way to do this?
l

Le Yang

04/18/2023, 2:10 PM
I believe the decorated return value should be
Output[None]
, not
None
itself.
j

Jan Hajny

04/18/2023, 2:14 PM
Thanks for the reply. Will that still ensure that any potential downstream assets understand that it never returns any values? As opposed to receiving an actual value of
None
?
l

Le Yang

04/18/2023, 2:18 PM
The special return type essentially turns off invoking the I/O Manager. You may use non_argument_dependencies if you want downstream assets to have dependency on this asset but not expecting any input value. https://docs.dagster.io/concepts/assets/software-defined-assets#non-argument-dependencies
j

Jan Hajny

04/18/2023, 2:19 PM
Oh yeah, the I/O manager invocation is also what I was worried about. Thanks a lot, this is very helpful!
l

Le Yang

04/18/2023, 2:39 PM
I'm learning myself too, trying to make sense of the different Dagster concepts and where to use what. It pays to actually read through the Concept section 😅
j

Jan Hajny

04/18/2023, 2:41 PM
True that 🙂 Anyway, thanks and good luck!
g

Giovanni Paolo

04/19/2023, 8:34 PM
personally I prefer to use context.add_output_metadata()
one fewer import, and no typehint shenanigans
l

Le Yang

04/19/2023, 8:36 PM
I think the issue is less about adding metadata but to avoid asset expectations that may never materialize
j

Jan Hajny

04/20/2023, 4:52 AM
It's kind of about both those things, thanks guys, both your advices are helpful 🙂