diff --git a/docs/how/updating-datahub.md b/docs/how/updating-datahub.md index 293e39e735e013..dbf2d4a0c5169a 100644 --- a/docs/how/updating-datahub.md +++ b/docs/how/updating-datahub.md @@ -31,6 +31,8 @@ This file documents any backwards-incompatible changes in DataHub and assists pe ``` Re-running with stateful ingestion should automatically clear up the entities with old URNS and add entities with new URNs, therefore not duplicating the containers or jobs. +- #11313 - `datahub get` will no longer return a key aspect for entities that don't exist. + ### Potential Downtime ### Deprecations diff --git a/metadata-ingestion/src/datahub/cli/get_cli.py b/metadata-ingestion/src/datahub/cli/get_cli.py index 27fa987ac79779..ab31323ac52b6f 100644 --- a/metadata-ingestion/src/datahub/cli/get_cli.py +++ b/metadata-ingestion/src/datahub/cli/get_cli.py @@ -48,16 +48,28 @@ def urn(ctx: Any, urn: Optional[str], aspect: List[str], details: bool) -> None: client = get_default_graph() + if aspect: + # If aspects are specified, we need to do the existence check first. + if not client.exists(urn): + raise click.ClickException(f"urn {urn} not found") + + aspect_data = get_aspects_for_entity( + session=client._session, + gms_host=client.config.server, + entity_urn=urn, + aspects=aspect, + typed=False, + details=details, + ) + + if not aspect: + # If no aspects are specified and we only get a key aspect back, yield an error instead. + if len(aspect_data) == 1 and "key" in next(iter(aspect_data)).lower(): + raise click.ClickException(f"urn {urn} not found") + click.echo( json.dumps( - get_aspects_for_entity( - session=client._session, - gms_host=client.config.server, - entity_urn=urn, - aspects=aspect, - typed=False, - details=details, - ), + aspect_data, sort_keys=True, indent=2, )