I have metadata on assets in my graph and I'm tryi...
# ask-community
d
I have metadata on assets in my graph and I'm trying to query that metadata through the graphql endpoint. However, the
metadataEntries
are empty for all of my asssets. example query:
Copy code
query RepositoriesQuery {
      repositoriesOrError {
        ... on RepositoryConnection {
          nodes {
            name
            assetNodes{
                assetKey {
                  path
                }
                metadataEntries {
                    label
                    description
                }
     ...
response has
metadataEntires:[]
for all assets despite seeing metadata in dagit.
🤖 1
s
Hi Drew, Are you able to create a minimal repro case? Like a
Definitions
object with one asset with metadata that is displaying this behavior.
d
Is there a simple dagster example repo somewhere? All the examples require environment variables and deployments and whatnot
But right now, I add metadata to all of my assets with
context.add_output_metadata()
in the
io-manager
and none of them have
metadataEntries
s
Ah-- that’s because
context.add_output_metadata
does not add metadata to the assets definition. That puts metadata on the
AssetMaterialization
event. The metadata on the definition, which is what you’re querying in that GQL query, is set like this (also an example of a simple example of the kind I’m talking about):
Copy code
from dagster import asset, Definitions

@asset(metadata={"foo": "bar"})
def foo_asset():
    return 1

defs = Definitions(
    assets=[foo_asset]
)
Put that in a file and run
dagster dev -f path/to/file
and your query should return the correct metadata.
d
is there a way to define asset metadata at output time in the io-manager?
s
There is not, but I think if you’re trying to do this you might have a fundamantal misconception of Dagster’s model. Dagster
AssetsDefinition
objects are basically wrappers around ops. They are a unit for buliding your data pipelines. They are defined when you load the code location, along with ops, jobs etc. They are not changed by Dagster runs. What is generated by runs are events. An
AssetMaterialization
is a kind of event, generated every time an asset’s materialization function is run. You modify the materialization generated by the current run when you use
add_output_metadata
.
d
So, I'm now doing
Copy code
assetMaterializations {
              timestamp
              metadataEntries {
                label
                description
              }
              partition
            }
I'm getting the correct labels but all of the
description
fields are
None
in the graphql response despite being populated in the dagit ui?
image.png
And from the
graphql
front-end (as well as from a python gql request):
Copy code
"path": [
                  "funding_rates_and_info"
                ]
              },
              "assetMaterializations": [
                {
                  "timestamp": "1684156958695",
                  "metadataEntries": [
                    {
                      "label": "uri",
                      "description": null
                    }
                  ],
                  "partition": null
                },
                {
                  "timestamp": "1683830321403",
                  "metadataEntries": [
                    {
                      "label": "path",
                      "description": null
                    }
                  ],
                  "partition": null
                }
              ],