Good day! I was wondering if there's a way within ...
# ask-community
s
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
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
@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
Not a built-in way, but you could do:
Copy code
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
@claire thanks for the suggestion! 👍 I'll give that a try!
🌈 1