|
5 | 5 | from typing import Optional |
6 | 6 |
|
7 | 7 | from pyatlan.client.common import AsyncApiCaller |
8 | | -from pyatlan.client.constants import CONTRACT_INIT_API |
| 8 | +from pyatlan.client.constants import ( |
| 9 | + CONTRACT_DELETE_SCOPE_HEADER, |
| 10 | + CONTRACT_INIT_API, |
| 11 | + DELETE_ENTITIES_BY_GUIDS, |
| 12 | +) |
9 | 13 | from pyatlan.errors import ErrorCode |
| 14 | +from pyatlan_v9.client.asset import _parse_mutation_response |
10 | 15 | from pyatlan_v9.model.assets import Asset |
11 | 16 | from pyatlan_v9.model.contract import InitRequest |
| 17 | +from pyatlan_v9.model.enums import AtlanDeleteType |
| 18 | +from pyatlan_v9.model.response import AssetMutationResponse |
12 | 19 | from pyatlan_v9.validate import validate_arguments |
13 | 20 |
|
14 | 21 |
|
@@ -48,3 +55,47 @@ async def generate_initial_spec( |
48 | 55 | CONTRACT_INIT_API, request_obj=request_obj |
49 | 56 | ) |
50 | 57 | return response.get("contract") |
| 58 | + |
| 59 | + @validate_arguments |
| 60 | + async def delete(self, guid: str) -> AssetMutationResponse: |
| 61 | + """ |
| 62 | + Hard-delete (purge) a data contract and all its versions (async version). |
| 63 | + This deletes every version of the contract associated with the same asset |
| 64 | + and cleans up the asset's contract attributes (hasContract, dataContractLatest, |
| 65 | + dataContractLatestCertified). |
| 66 | +
|
| 67 | + :param guid: unique identifier (GUID) of any version of the contract to delete |
| 68 | + :returns: details of the deleted contract version(s) |
| 69 | + :raises AtlanError: on any API communication issue |
| 70 | +
|
| 71 | + .. warning:: |
| 72 | + This is an irreversible operation. All versions of the contract will be permanently removed. |
| 73 | + """ |
| 74 | + query_params = {"deleteType": AtlanDeleteType.PURGE.value, "guid": [guid]} |
| 75 | + raw_json = await self._client._call_api( |
| 76 | + DELETE_ENTITIES_BY_GUIDS, query_params=query_params |
| 77 | + ) |
| 78 | + return _parse_mutation_response(raw_json) |
| 79 | + |
| 80 | + @validate_arguments |
| 81 | + async def delete_latest_version(self, guid: str) -> AssetMutationResponse: |
| 82 | + """ |
| 83 | + Hard-delete (purge) only the latest version of a data contract (async version). |
| 84 | + The previous version (if any) becomes the new latest, and the asset's |
| 85 | + contract pointers are updated accordingly. |
| 86 | +
|
| 87 | + :param guid: unique identifier (GUID) of the latest contract version to delete |
| 88 | + :returns: details of the deleted contract version |
| 89 | + :raises AtlanError: on any API communication issue |
| 90 | + :raises ApiError: if the specified GUID is not the latest version |
| 91 | +
|
| 92 | + .. warning:: |
| 93 | + This is an irreversible operation. Only the latest version will be removed. |
| 94 | + """ |
| 95 | + query_params = {"deleteType": AtlanDeleteType.PURGE.value, "guid": [guid]} |
| 96 | + raw_json = await self._client._call_api( |
| 97 | + DELETE_ENTITIES_BY_GUIDS, |
| 98 | + query_params=query_params, |
| 99 | + extra_headers={CONTRACT_DELETE_SCOPE_HEADER: "single"}, |
| 100 | + ) |
| 101 | + return _parse_mutation_response(raw_json) |
0 commit comments