Skip to content

fix(delete): Fix soft delete crash when sketch was soft_deleted - #3860

Open
jaegeral wants to merge 9 commits into
google:masterfrom
jaegeral:2026-06-22-cli-soft-delete-crash
Open

fix(delete): Fix soft delete crash when sketch was soft_deleted#3860
jaegeral wants to merge 9 commits into
google:masterfrom
jaegeral:2026-06-22-cli-soft-delete-crash

Conversation

@jaegeral

@jaegeral jaegeral commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

This pull request resolves an issue where attempting to delete a soft-deleted sketch via the CLI fails.

It handles exceptions raised when lazy-loading timeline info on soft-deleted sketches, defaulting these values to 'N/A'.

Fwiw, we made the decision back when we implemented deletion, that only admins can see soft-deleted sketches (also in the sketch-list with include_deleted=true . And currently we do not have a flag for include_deleted in the pull single sketch endpoint (which would be only usable by admins).

@jaegeral

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request resolves an issue where attempting to delete a soft-deleted sketch via the CLI fails. It handles RuntimeError exceptions raised when lazy-loading timeline descriptions and statuses on soft-deleted sketches, defaulting these values to 'N/A'. It also adds an end-to-end integration test to verify this scenario. The review feedback correctly identifies a style guide violation regarding exception handling, noting that the exception should be caught using the 'as e:' syntax (i.e., 'except RuntimeError as e:').

Comment thread cli_client/python/timesketch_cli_client/commands/sketch.py Outdated
jaegeral and others added 5 commits June 22, 2026 15:30
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@jaegeral

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request improves the handling of soft-deleted or inaccessible sketches in the CLI client by catching NotFoundError and gracefully falling back to default values, alongside adding corresponding end-to-end tests. The review feedback correctly identifies several violations of the repository style guide regarding exception handling, specifically the requirement to use the 'as e:' syntax when catching exceptions, and suggests a refactoring to reduce code duplication.

Comment thread cli_client/python/timesketch_cli_client/commands/sketch.py Outdated
Comment thread cli_client/python/timesketch_cli_client/commands/sketch.py Outdated
Comment thread cli_client/python/timesketch_cli_client/commands/sketch.py
@jaegeral
jaegeral requested a review from jkppr June 22, 2026 15:05
@jaegeral
jaegeral marked this pull request as ready for review June 22, 2026 15:06
@jaegeral jaegeral changed the title fix(delete): Fix soft delete crash fix(delete): Fix soft delete crash when sketch was soft_deleted Jun 22, 2026

@jkppr jkppr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fwiw, catching NotFoundError in the CLI feels a bit like a band-aid for API limitations. If we instead update the server-side API (e.g., _get_sketch_for_admin) to return basic timeline metadata (just names/IDs from DB, skipping OpenSearch calls) for soft-deleted sketches when accessed by admins, we could avoid these try-catch blocks in the CLI entirely.

WDYT?

sketch_desc = sketch.description
sketch_status = sketch.status
sketch_labels = sketch.labels
timelines = sketch.list_timelines()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If I'm not mistaken, the API (_get_sketch_for_admin) returns timelines: []. This means for admins, the dry-run here will show no timelines, but --force_delete will still permanently delete them from the DB.

That seems a bit risky because the admin won't see what they are actually deleting. Or is this intentional?

f"Warning: Sketch {sketch.id} appears to be soft-deleted or inaccessible."
)
if not force_delete:
click.echo("If you want to permanently delete it, use --force_delete")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't this guidance a bit misleading? We only enter this except NotFoundError block if the sketch doesn't exist at all, or if the user is a non-admin (since admins can check archived status on soft-deleted sketches without triggering a 404).

In both cases, telling them to try --force_delete will just lead to another failure (either because they aren't an admin, or because the sketch genuinely doesn't exist). Maybe we should just report it as not found or inaccessible without suggesting --force_delete?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants