Area: Product
Sub-Area: Versioning
Applies to: OSS + Cloud
Issue
You want to see how an asset's metadata changed over time. For example, who changed a dataset's description last month, or what its properties held before an ingestion run replaced them. You may also want to put back an earlier value.
You Might Be Asking
- Can I see what a dataset looked like last month?
- How do I see the change history of a dataset's description, tags or schema?
- Can I read or restore an earlier version of an aspect?
- Ingestion overwrote the custom properties on my dataset. Can I get the previous datasetProperties back?
Cause
DataHub stores metadata in aspects (for example datasetProperties, globalTags, schemaMetadata). Each write to an aspect saves the previous value as a new version.
- Version 0 is always the current value. Earlier versions are numbered from 1 (oldest) upward, so the highest number is the newest previous value, not the current one.
- DataHub does not keep every version. Retention is on by default and keeps the 20 most recent versions of each aspect on each entity. Older versions are deleted, and the remaining versions keep their numbers. Changes older than what retention kept can't be read or shown. See Configuring Database Retention.
- The GraphQL
aspectsfield does not return history. It takes onlyautoRenderOnlyandaspectNamesand returns the currentaspectName,payloadandrenderSpec. It has noaspectName,versionormaxCountinput and noversionorcreatedoutput.
Solution
See what changed and when (Timeline API)
The Timeline API lists the changes to an entity, grouped by category. For datasets, the categories include DOCUMENTATION, TAG, GLOSSARY_TERM, TECHNICAL_SCHEMA and DOMAIN. DOCUMENTATION covers changes to the ingested description in datasetProperties and the description edited in DataHub in editableDatasetProperties. It also covers links and field descriptions.
For datasetProperties, the timeline reports only changes to description. A change to only customProperties or the name creates no change event, so it does not appear in the timeline, even with --raw. To see earlier custom property values, use get_aspect with a version number, as shown in the next section.
With the DataHub CLI, after you connect it to your instance with datahub init:
datahub timeline --urn "urn:li:dataset:(urn:li:dataPlatform:snowflake,db.schema.table,PROD)" --category documentation --category tag --start 30daysago
-
--startand--endtake epoch milliseconds or the form30daysago. - If you leave out
--start, you get only the last 7 days. - Add
--rawto include the raw JSON diff of each change, or--verboseto print the full JSON response.
With REST, call the same endpoint the CLI uses. URL-encode the URN and give times in epoch milliseconds:
GET <your-gms-url>/openapi/v2/timeline/v1/<url-encoded-urn>?categories=DOCUMENTATION,TAG&startTime=1735689600000&endTime=1738368000000
The time parameters are startTime and endTime. The server ignores other names, such as start and end, and falls back to the last 7 days. More detail is in Timeline API.
Read an earlier version of an aspect
Use get_aspect from the Python SDK with the version argument. version=0 (the default) is the current value.
from datahub.ingestion.graph.client import DataHubGraph, DatahubClientConfig
from datahub.metadata.schema_classes import DatasetPropertiesClass
graph = DataHubGraph(DatahubClientConfig(server="<your-gms-url>", token="<your-token>"))
urn = "urn:li:dataset:(urn:li:dataPlatform:snowflake,db.schema.table,PROD)"
old = graph.get_aspect(urn, DatasetPropertiesClass, version=5)
if old is None:
print("Version 5 is not stored")
else:
print(old.description, old.customProperties)
get_aspect returns None when that version does not exist, for example because retention deleted it. The numbering is explained in Aspect Versioning.
Restore an earlier version
To put an earlier value back, emit it as a new write:
from datahub.emitter.mcp import MetadataChangeProposalWrapper
graph.emit_mcp(MetadataChangeProposalWrapper(entityUrn=urn, aspect=old))
- This replaces the whole current aspect with the old one. Each field that changed after that version (description, name, custom properties) goes back to the old value. Read the current value first (
version=0) and keep a copy. -
emit_mcptakes oneMetadataChangeProposalWrapper. It has noentity_urn,aspect_nameoraspectarguments. - If an ingestion source writes this aspect, its next run replaces your restored value.
-
datahub ingest rollbackis not a way to restore an aspect version. It undoes everything an ingestion run wrote.
Related Documentation
- Timeline API
- Aspect Versioning
- Configuring Database Retention
- What is a metadata aspect?
- DataHub CLI: timeline
Tags: time-travel, versioning, historical-data, metadata-history, audit, timeline, change-tracking, retention, custom-properties, restore, ingestion-overwrote