fix(cli): list-source-runs added null checking (#12369)

This commit is contained in:
kevinkarchacryl 2025-01-16 15:28:42 -05:00 committed by GitHub
parent 0ddf88651d
commit bfe975874d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 19 deletions

View File

@ -115,17 +115,17 @@ datahub ingest -c ./examples/recipes/example_to_datahub_rest.dhub.yaml --dry-run
datahub ingest -c ./examples/recipes/example_to_datahub_rest.dhub.yaml -n
```
#### ingest --list-source-runs
#### ingest list-source-runs
The `--list-source-runs` option of the `ingest` command lists the previous runs, displaying their run ID, source name,
The `list-source-runs` option of the `ingest` command lists the previous runs, displaying their run ID, source name,
start time, status, and source URN. This command allows you to filter results using the --urn option for URN-based
filtering or the --source option to filter by source name (partial or complete matches are supported).
```shell
# List all ingestion runs
datahub ingest --list-source-runs
datahub ingest list-source-runs
# Filter runs by a source name containing "demo"
datahub ingest --list-source-runs --source "demo"
datahub ingest list-source-runs --source "demo"
```
#### ingest --preview

View File

@ -507,15 +507,11 @@ def list_source_runs(page_offset: int, page_size: int, urn: str, source: str) ->
click.echo("No response received from the server.")
return
# when urn or source filter does not match, exit gracefully
if (
not isinstance(data.get("data"), dict)
or "listIngestionSources" not in data["data"]
):
click.echo("No matching ingestion sources found. Please check your filters.")
return
# a lot of responses can be null if there's errors in the run
ingestion_sources = (
data.get("data", {}).get("listIngestionSources", {}).get("ingestionSources", [])
)
ingestion_sources = data["data"]["listIngestionSources"]["ingestionSources"]
if not ingestion_sources:
click.echo("No ingestion sources or executions found.")
return
@ -526,18 +522,32 @@ def list_source_runs(page_offset: int, page_size: int, urn: str, source: str) ->
name = ingestion_source.get("name", "N/A")
executions = ingestion_source.get("executions", {}).get("executionRequests", [])
for execution in executions:
if execution is None:
continue
execution_id = execution.get("id", "N/A")
start_time = execution.get("result", {}).get("startTimeMs", "N/A")
start_time = (
datetime.fromtimestamp(start_time / 1000).strftime("%Y-%m-%d %H:%M:%S")
if start_time != "N/A"
else "N/A"
)
status = execution.get("result", {}).get("status", "N/A")
result = execution.get("result") or {}
status = result.get("status", "N/A")
try:
start_time = (
datetime.fromtimestamp(
result.get("startTimeMs", 0) / 1000
).strftime("%Y-%m-%d %H:%M:%S")
if status != "DUPLICATE" and result.get("startTimeMs") is not None
else "N/A"
)
except (TypeError, ValueError):
start_time = "N/A"
rows.append([execution_id, name, start_time, status, urn])
if not rows:
click.echo("No execution data found.")
return
click.echo(
tabulate(
rows,