Skip to content

Commit

Permalink
feat(cli): reject missing urns in datahub get (#11313)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored Sep 6, 2024
1 parent 0ce9e94 commit 607ad5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/how/updating-datahub.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions metadata-ingestion/src/datahub/cli/get_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit 607ad5e

Please sign in to comment.