the following asset: ```@asset def some_asset(): ...
# ask-community
p
the following asset:
Copy code
@asset
def some_asset():
    
    output = "some_great_output"

    return Output(
        value=output,
        output_name=some_name,
    )
raises this error:
Copy code
dagster._core.errors.DagsterInvariantViolationError: Bad state: Output was explicitly named 'some_name', which does not match the output definition specified for position 0: 'result'.
how do i fix this?
y
Copy code
@asset
def some_asset():
    
    output = "some_great_output"

    return Output(
        value=output,
    )
you don’t need to specify the name
to make it even simpler, you can directly return the value as:
Copy code
@asset
def some_asset():
    
    output = "some_great_output"

    return output
because
@asset
would yield only one output, which is considered as “the data asset” tied to this computation. if you’d like to yield multiple outputs in one asset, you can use
@multi_assets
https://docs.dagster.io/concepts/assets/multi-assets where you can give names to different outputs
p
thanks @yuhan! i know i don’t need to specify an output name, but i want to. i feel there are cases where you need to wrap your output into an
Output
object even for a (non-multi) asset, e.g. to attach metadata to it (correct me if that’s wrong). but if you wrap your output into an
Output
object, the asset gets the default name “result” - not exactly a very useful name for an asset. hence my need to give it an explicit name. that should be possible somehow, right?
Since the
asset
decorator does not expect an
output_defs
parameter or an
outs
parameter or anything like that, how do you specify an
OutputDefinition
for it?
y
if you’d want to attach metadata to an asset output, you can use
context.add_output_metadata
too. here’s an example: https://github.com/dagster-io/dagster/blob/master/examples/quickstart_etl/quickstart_etl/assets/hackernews.py#L40-L49 as for “result” isn’t useful name, when you’re using the single asset with single output (1:1 mapping), the name “result” becomes an implementation detail because the output metadata will show up in that asset page, which is why
@asset
doesn’t have the
outs
argument bc it doesn’t need to. that being said, if you do need to
return Output
, you can
return Output(name="result",…)
👍 1
🌈 1