From c8dbe47f1fb714def2e91ea971e086ed877b9308 Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Tue, 29 Oct 2024 21:40:55 +0530 Subject: [PATCH 1/2] feat(ingest/cli): add undo soft delete command --- .../src/datahub/cli/delete_cli.py | 11 +++++++++++ .../src/datahub/ingestion/graph/client.py | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/metadata-ingestion/src/datahub/cli/delete_cli.py b/metadata-ingestion/src/datahub/cli/delete_cli.py index 584bfc1f7cda5..6c5b5002c5d96 100644 --- a/metadata-ingestion/src/datahub/cli/delete_cli.py +++ b/metadata-ingestion/src/datahub/cli/delete_cli.py @@ -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: + """ + Allows to un-soft delete by filters + """ + graph = get_default_graph() + logger.info(f"Using {graph}") + graph.change_soft_delete_status(urn=urn, delete=False) + + @delete.command(no_args_is_help=True) @click.option( "--urn", diff --git a/metadata-ingestion/src/datahub/ingestion/graph/client.py b/metadata-ingestion/src/datahub/ingestion/graph/client.py index 1d2528a24c4e5..83af15dbc7365 100644 --- a/metadata-ingestion/src/datahub/ingestion/graph/client.py +++ b/metadata-ingestion/src/datahub/ingestion/graph/client.py @@ -1241,14 +1241,29 @@ def soft_delete_entity( Args: urn: The urn of the entity to soft-delete. """ + self.change_soft_delete_status( + urn=urn, run_id=run_id, deletion_timestamp=deletion_timestamp, delete=True + ) + + def change_soft_delete_status( + self, + urn: str, + delete: bool, + 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 ), From e4bdf538d8bb40c489ddf0b5a64ace0f3ff64534 Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Mon, 4 Nov 2024 14:40:17 +0530 Subject: [PATCH 2/2] code review feedback --- metadata-ingestion/src/datahub/cli/delete_cli.py | 4 ++-- metadata-ingestion/src/datahub/ingestion/graph/client.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/metadata-ingestion/src/datahub/cli/delete_cli.py b/metadata-ingestion/src/datahub/cli/delete_cli.py index 6c5b5002c5d96..8b852513e03c0 100644 --- a/metadata-ingestion/src/datahub/cli/delete_cli.py +++ b/metadata-ingestion/src/datahub/cli/delete_cli.py @@ -217,11 +217,11 @@ def references(urn: str, dry_run: bool, force: bool) -> None: @click.option("--urn", required=True, type=str, help="the urn of the entity") def undo_by_filter(urn: str) -> None: """ - Allows to un-soft delete by filters + Undo a soft deletion of an entity """ graph = get_default_graph() logger.info(f"Using {graph}") - graph.change_soft_delete_status(urn=urn, delete=False) + graph.set_soft_delete_status(urn=urn, delete=False) @delete.command(no_args_is_help=True) diff --git a/metadata-ingestion/src/datahub/ingestion/graph/client.py b/metadata-ingestion/src/datahub/ingestion/graph/client.py index 83af15dbc7365..c90ac93eee2cc 100644 --- a/metadata-ingestion/src/datahub/ingestion/graph/client.py +++ b/metadata-ingestion/src/datahub/ingestion/graph/client.py @@ -1241,11 +1241,11 @@ def soft_delete_entity( Args: urn: The urn of the entity to soft-delete. """ - self.change_soft_delete_status( + self.set_soft_delete_status( urn=urn, run_id=run_id, deletion_timestamp=deletion_timestamp, delete=True ) - def change_soft_delete_status( + def set_soft_delete_status( self, urn: str, delete: bool,