Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was always "datahub ingest list-source-runs" so just correcting the doc here

#### 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
Expand Down
40 changes: 25 additions & 15 deletions metadata-ingestion/src/datahub/cli/ingest_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,11 @@
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 = (

Check warning on line 511 in metadata-ingestion/src/datahub/cli/ingest_cli.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/cli/ingest_cli.py#L511

Added line #L511 was not covered by tests
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
Expand All @@ -526,18 +522,32 @@
name = ingestion_source.get("name", "N/A")

executions = ingestion_source.get("executions", {}).get("executionRequests", [])

for execution in executions:
if execution is None:
continue

Check warning on line 528 in metadata-ingestion/src/datahub/cli/ingest_cli.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/cli/ingest_cli.py#L527-L528

Added lines #L527 - L528 were not covered by tests

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")

Check warning on line 532 in metadata-ingestion/src/datahub/cli/ingest_cli.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/cli/ingest_cli.py#L531-L532

Added lines #L531 - L532 were not covered by tests

try:
start_time = (

Check warning on line 535 in metadata-ingestion/src/datahub/cli/ingest_cli.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/cli/ingest_cli.py#L534-L535

Added lines #L534 - L535 were not covered by tests
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"

Check warning on line 543 in metadata-ingestion/src/datahub/cli/ingest_cli.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/cli/ingest_cli.py#L542-L543

Added lines #L542 - L543 were not covered by tests

rows.append([execution_id, name, start_time, status, urn])

if not rows:
click.echo("No execution data found.")
return

Check warning on line 549 in metadata-ingestion/src/datahub/cli/ingest_cli.py

View check run for this annotation

Codecov / codecov/patch

metadata-ingestion/src/datahub/cli/ingest_cli.py#L547-L549

Added lines #L547 - L549 were not covered by tests

click.echo(
tabulate(
rows,
Expand Down
Loading