Hi, <https://docs.dagster.io/concepts/assets/softw...
# ask-community
d
Hi, https://docs.dagster.io/concepts/assets/software-defined-assets#conditional-materialization I want to implement Conditional materialization so that on some condition dowstream stops but when I do the same as in the link example I get this error:
Copy code
Value "None" returned for non-required output "result" of op "filepaths". This value will be passed to downstream ops. For conditional execution, results must be yielded: <https://docs.dagster.io/concepts/ops-jobs-graphs/graphs#with-conditional-branching>
nothing stops there and downstream assets try to materialize 😞 Then If I try to just
yield
nothing I get
Copy code
dagster._core.errors.DagsterInvariantViolationError: Compute function for op "filepaths" yielded a value of type <class 'NoneType'> rather than an instance of Output, AssetMaterialization, or ExpectationResult. Values yielded by ops must be wrapped in one of these types. If your op has a single output and yields no other events, you may want to use `return` instead of `yield` in the body of your op compute function. If you are already using `return`, and you expected to return a value of type <class 'NoneType'>, you may be inadvertently returning a generator rather than the value
Then If I try to
yield Output(None)
Asset gets materialized and downstream tries to materialize too
🤖 1
j
Hey @Deividas Jodogalvis I think the intricacy here is that the value for when the asset it supposed to materialize should be `yield`ed as an
Output
but when the asset shouldn’t do anything, the function doesn’t do anything (ie an implicit
return None
) In this example
Copy code
@asset(output_required=False)
def may_not_materialize():
    # to simulate an asset that may not always materialize.
    if random.randint(1, 10) < 5:
        yield Output([1, 2, 3, 4])


@asset
def downstream(may_not_materialize):
    # will not run when may_not_materialize doesn't materialize the asset
    return may_not_materialize + [5]
notice how when the random int is >= 5 the function doesn’t do anything https://docs.dagster.io/concepts/assets/software-defined-assets#conditional-materialization
d
Thanks! I found my problem my code was smth like this:
Copy code
@asset(output_required=False)
def may_not_materialize():
    variable = 123
and this does not work, not sure why If I add for example this, it works, no matter yield code part is unreachable
Copy code
@asset(output_required=False)
def may_not_materialize():
    variable = 123
    if 0==1:
        yield Output(value=9)