Stephen Bailey
10/13/2022, 5:27 PM@asset
def my_asset():
# code to actually create the asset
object_id = do_something()
# code to do a /describe call from an api
details = requests.get(f"some_url/{object_id")
context.add_output_metadata(details)
return object_id
However, we frequently hit errors in the ops this way, especially around array values: dagster._core.errors.DagsterInvalidMetadata: Could not resolve the metadata value for "public_access_id" to a known type. Its type was <class 'NoneType'>. Consider wrapping the value with the appropriate MetadataValue type.
. Would be great to have a sanitize_metadata
argument that by default drops unparseable values, or something.geoHeil
10/13/2022, 8:20 PMStephen Bailey
10/14/2022, 11:58 AMdef sanitize_metadata_dict(metadata_dict: dict) -> dict:
"Sanitizes a raw Python dict so that it can be cast to Dagster metadata"
sanitized = dict()
for k, v in metadata_dict.items():
if isinstance(v, str):
sanitized[k] = v
elif isinstance(v, int) or isinstance(v, float):
sanitized[k] = v
elif isinstance(v, dict):
sanitized[k] = sanitize_metadata_dict(v)
else:
logger.debug("Noncompliant metadata key found (%s). Removing.", type(v))
return sanitized
chris
10/18/2022, 9:35 PMStephen Bailey
10/19/2022, 1:17 PMlist
, would be great to handle that too