https://dagster.io/ logo
Title
s

Simon

02/23/2023, 10:21 PM
Good day! I was wondering if there's a way within an Op to get the key(s) of the input Asset(s) for that Op?
c

claire

02/24/2023, 12:22 AM
Hi Simon. It is possible within an asset to get the upstream asset keys. Are you referring to how to get the input assets for an op within a graph-backed asset?
s

Simon

02/24/2023, 4:15 PM
@claire yeah, correct. Trying get the Asset key of the Asset that's the input to an Op that's part of a graph backed Asset
c

claire

02/24/2023, 8:28 PM
Not a built-in way, but you could do:
dep_node_handles_by_asset_key = context.job_def.asset_layer._dependency_node_handles_by_asset_key
dep_asset_keys = {k for k, v in dep_node_handles_by_asset_key.items() if context.op_handle in v}
The above code snippet is untested, but basically
_dependency_node_handles_by_asset_key
maps all input asset keys to the ops within the graph that rely on it (not just direct downstream dependencies, but all dependencies within the graph). Then you can filter out which input asset keys the current node relies on by checking if the current op is in the downstream deps for a given asset key.
s

Simon

02/24/2023, 9:11 PM
@claire thanks for the suggestion! 👍 I'll give that a try!
:rainbow-daggy: 1