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

feat(ingest/cli): add undo soft delete command #11740

Merged
merged 3 commits into from
Nov 4, 2024
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
11 changes: 11 additions & 0 deletions metadata-ingestion/src/datahub/cli/delete_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ def references(urn: str, dry_run: bool, force: bool) -> None:
logger.info(f"Deleted {references_count} references to {urn}")


@delete.command()
@click.option("--urn", required=True, type=str, help="the urn of the entity")
def undo_by_filter(urn: str) -> None:
anshbansal marked this conversation as resolved.
Show resolved Hide resolved
"""
Undo a soft deletion of an entity
"""
graph = get_default_graph()
logger.info(f"Using {graph}")
graph.set_soft_delete_status(urn=urn, delete=False)


@delete.command(no_args_is_help=True)
@click.option(
"--urn",
Expand Down
17 changes: 16 additions & 1 deletion metadata-ingestion/src/datahub/ingestion/graph/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,14 +1241,29 @@ def soft_delete_entity(
Args:
urn: The urn of the entity to soft-delete.
"""
self.set_soft_delete_status(
urn=urn, run_id=run_id, deletion_timestamp=deletion_timestamp, delete=True
)

def set_soft_delete_status(
self,
urn: str,
delete: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
delete: bool,
deleted: bool,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

delete is correct here

run_id: str = _GRAPH_DUMMY_RUN_ID,
deletion_timestamp: Optional[int] = None,
) -> None:
"""Change status of soft-delete an entity by urn.

Args:
urn: The urn of the entity to soft-delete.
"""
assert urn

deletion_timestamp = deletion_timestamp or int(time.time() * 1000)
self.emit(
MetadataChangeProposalWrapper(
entityUrn=urn,
aspect=StatusClass(removed=True),
aspect=StatusClass(removed=delete),
systemMetadata=SystemMetadataClass(
runId=run_id, lastObserved=deletion_timestamp
),
Expand Down
Loading