Skip to content

Commit 935becb

Browse files
authored
Merge pull request #674 from atlanhq/APP-6910
[test] Fixed `suggestions_test` and added `delete_type` param to `purge_by_guid()` method
2 parents ed1e0a9 + 7f29b5a commit 935becb

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

pyatlan/client/asset.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,21 +786,32 @@ def update_replacing_cm(
786786
)
787787

788788
@validate_arguments
789-
def purge_by_guid(self, guid: Union[str, List[str]]) -> AssetMutationResponse:
789+
def purge_by_guid(
790+
self,
791+
guid: Union[str, List[str]],
792+
delete_type: AtlanDeleteType = AtlanDeleteType.PURGE,
793+
) -> AssetMutationResponse:
790794
"""
791-
Hard-deletes (purges) one or more assets by their unique identifier (GUID).
792-
This operation is irreversible.
795+
Deletes one or more assets by their unique identifier (GUID) using the specified delete type.
796+
797+
:param guid: unique identifier(s) (GUIDs) of one or more assets to delete
798+
:param delete_type: type of deletion to perform:
793799
794-
:param guid: unique identifier(s) (GUIDs) of one or more assets to hard-delete
795-
:returns: details of the hard-deleted asset(s)
800+
- PURGE: completely removes entity and all audit/history traces (default, irreversible)
801+
- HARD: physically removes entity but keeps audit history (irreversible)
802+
803+
:returns: details of the deleted asset(s)
796804
:raises AtlanError: on any API communication issue
805+
806+
.. warning::
807+
PURGE and HARD deletions are irreversible operations. Use with caution.
797808
"""
798809
guids: List[str] = []
799810
if isinstance(guid, list):
800811
guids.extend(guid)
801812
else:
802813
guids.append(guid)
803-
query_params = {"deleteType": AtlanDeleteType.PURGE.value, "guid": guids}
814+
query_params = {"deleteType": delete_type.value, "guid": guids}
804815
raw_json = self._client._call_api(
805816
DELETE_ENTITIES_BY_GUIDS, query_params=query_params
806817
)

tests/integration/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
from pyatlan.client.atlan import AtlanClient
9+
from pyatlan.model.enums import AtlanDeleteType
910
from pyatlan.model.response import A
1011

1112
LOGGER = logging.getLogger(__name__)
@@ -31,9 +32,14 @@ def client() -> Generator[AtlanClient, None, None]:
3132
yield client
3233

3334

34-
def delete_asset(client: AtlanClient, asset_type: Type[A], guid: str) -> None:
35+
def delete_asset(
36+
client: AtlanClient,
37+
asset_type: Type[A],
38+
guid: str,
39+
delete_type: AtlanDeleteType = AtlanDeleteType.PURGE,
40+
) -> None:
3541
# These assertions check the cleanup actually worked
36-
r = client.asset.purge_by_guid(guid)
42+
r = client.asset.purge_by_guid(guid, delete_type)
3743
s = r is not None
3844
s = s and len(r.assets_deleted(asset_type)) == 1
3945
s = s and r.assets_deleted(asset_type)[0].guid == guid

tests/integration/suggestions_test.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Callable, Generator
33

44
import pytest
5+
from pydantic import StrictStr
56

67
from pyatlan.client.atlan import AtlanClient
78
from pyatlan.model.assets import (
@@ -16,7 +17,7 @@
1617
View,
1718
)
1819
from pyatlan.model.core import AtlanTag, AtlanTagName
19-
from pyatlan.model.enums import AtlanConnectorType
20+
from pyatlan.model.enums import AtlanConnectorType, AtlanDeleteType
2021
from pyatlan.model.group import AtlanGroup
2122
from pyatlan.model.response import AssetMutationResponse
2223
from pyatlan.model.suggestions import Suggestions
@@ -47,6 +48,23 @@
4748
TERM_NAME2 = PREFIX + "term2"
4849

4950

51+
def create_glossary(client: AtlanClient, name: str) -> AtlasGlossary:
52+
g = AtlasGlossary.create(name=StrictStr(name))
53+
r = client.asset.save(g)
54+
return r.assets_created(AtlasGlossary)[0]
55+
56+
57+
@pytest.fixture(scope="module")
58+
def glossary(
59+
client: AtlanClient,
60+
) -> Generator[AtlasGlossary, None, None]:
61+
g = create_glossary(client, PREFIX)
62+
yield g
63+
delete_asset(
64+
client, guid=g.guid, asset_type=AtlasGlossary, delete_type=AtlanDeleteType.HARD
65+
)
66+
67+
5068
@pytest.fixture(scope="module")
5169
def wait_for_consistency():
5270
"""
@@ -383,7 +401,12 @@ def term1(
383401
qualified_name=t1c1.qualified_name,
384402
terms=[AtlasGlossaryTerm.ref_by_guid(t.guid)],
385403
)
386-
delete_asset(client, guid=t.guid, asset_type=AtlasGlossaryTerm)
404+
delete_asset(
405+
client,
406+
guid=t.guid,
407+
asset_type=AtlasGlossaryTerm,
408+
delete_type=AtlanDeleteType.HARD,
409+
)
387410

388411

389412
@pytest.fixture(scope="module")
@@ -427,7 +450,12 @@ def term2(
427450
qualified_name=v1c1.qualified_name,
428451
terms=[AtlasGlossaryTerm.ref_by_guid(t.guid)],
429452
)
430-
delete_asset(client, guid=t.guid, asset_type=AtlasGlossaryTerm)
453+
delete_asset(
454+
client,
455+
guid=t.guid,
456+
asset_type=AtlasGlossaryTerm,
457+
delete_type=AtlanDeleteType.HARD,
458+
)
431459

432460

433461
@pytest.fixture(scope="module")
@@ -485,7 +513,9 @@ def table3(
485513
assert (tables := response.assets_created(asset_type=Table))
486514
assert len(tables) == 1
487515
yield tables[0]
488-
# delete_asset(client, guid=tables[0].guid, asset_type=Table)
516+
delete_asset(
517+
client, guid=tables[0].guid, asset_type=Table, delete_type=AtlanDeleteType.HARD
518+
)
489519

490520

491521
def test_tables(

0 commit comments

Comments
 (0)