Skip to content

Commit 6bbf207

Browse files
committed
[refactor] Improved MISSING_DATA_PRODUCT_ASSET_DSL custom error
1 parent 0885097 commit 6bbf207

File tree

5 files changed

+44
-49
lines changed

5 files changed

+44
-49
lines changed

pyatlan/errors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,12 @@ class ErrorCode(Enum):
629629
"Set `test` to `True` or remove `username` and `password`.",
630630
InvalidRequestError,
631631
)
632-
MISSING_DP_Asset_DSL = (
632+
MISSING_DATA_PRODUCT_ASSET_DSL = (
633633
400,
634634
"ATLAN-PYTHON-400-072",
635-
"No DataProduct Aseet DSL was found.",
636-
"You must provide a DataProduct asset DSL when retrieving DataProduct assets.",
637-
NotFoundError,
635+
"Missing value for `data_product_assets_d_s_l`, which is required to retrieve DataProduct assets.",
636+
"Ensure your product instance has a valid `data_product_assets_d_s_l` value before making the request.",
637+
InvalidRequestError,
638638
)
639639
AUTHENTICATION_PASSTHROUGH = (
640640
401,

pyatlan/generator/templates/methods/asset/data_product.jinja2

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,17 @@
9090
Reterieves list of all assets linked to the provided data product.
9191

9292
:param client: connectivity to an Atlan tenant (optional). If not provided, the default client will be used.
93-
94-
:raises NotFoundError: if DataProduct asset DSL cannot be found (does not exist) in Atlan
93+
:raises InvalidRequestError: if DataProduct asset DSL cannot be found (does not exist) in Atlan
9594
:raises AtlanError: if there is an issue interacting with the API
9695
:returns: instance of `IndexSearchResults` with list of all assets linked to the provided data product
97-
9896
"""
9997
from pyatlan.client.atlan import AtlanClient
10098

10199
client = AtlanClient.get_current_client() if not client else client
102100
dp_dsl = self.data_product_assets_d_s_l
103-
if dp_dsl:
104-
json_object = json.loads(dp_dsl) if dp_dsl else {}
105-
request = IndexSearchRequest(**json_object.get("query", {}))
106-
response = client.asset.search(request)
107-
else:
108-
raise ErrorCode.MISSING_DP_Asset_DSL.exception_with_parameters()
101+
if not dp_dsl:
102+
raise ErrorCode.MISSING_DATA_PRODUCT_ASSET_DSL.exception_with_parameters()
103+
json_object = json.loads(dp_dsl)
104+
request = IndexSearchRequest(**json_object.get("query", {}))
105+
response = client.asset.search(request)
109106
return response

pyatlan/model/assets/core/data_product.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,19 @@ def get_assets(self, client: Optional[AtlanClient] = None):
129129
Reterieves list of all assets linked to the provided data product.
130130
131131
:param client: connectivity to an Atlan tenant (optional). If not provided, the default client will be used.
132-
133-
:raises NotFoundError: if DataProduct asset DSL cannot be found (does not exist) in Atlan
132+
:raises InvalidRequestError: if DataProduct asset DSL cannot be found (does not exist) in Atlan
134133
:raises AtlanError: if there is an issue interacting with the API
135134
:returns: instance of `IndexSearchResults` with list of all assets linked to the provided data product
136-
137135
"""
138136
from pyatlan.client.atlan import AtlanClient
139137

140138
client = AtlanClient.get_current_client() if not client else client
141139
dp_dsl = self.data_product_assets_d_s_l
142-
if dp_dsl:
143-
json_object = json.loads(dp_dsl) if dp_dsl else {}
144-
request = IndexSearchRequest(**json_object.get("query", {}))
145-
response = client.asset.search(request)
146-
else:
147-
raise ErrorCode.MISSING_DP_Asset_DSL.exception_with_parameters()
140+
if not dp_dsl:
141+
raise ErrorCode.MISSING_DATA_PRODUCT_ASSET_DSL.exception_with_parameters()
142+
json_object = json.loads(dp_dsl)
143+
request = IndexSearchRequest(**json_object.get("query", {}))
144+
response = client.asset.search(request)
148145
return response
149146

150147
type_name: str = Field(default="DataProduct", allow_mutation=False)

tests/integration/data_mesh_test.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from pyatlan.client.asset import IndexSearchResults
88
from pyatlan.client.atlan import AtlanClient
9-
from pyatlan.errors import NotFoundError
109
from pyatlan.model.assets import (
1110
Asset,
1211
AtlasGlossary,
@@ -503,26 +502,6 @@ def test_product_get_assets(client: AtlanClient, product: DataProduct):
503502
assert isinstance(asset_list, IndexSearchResults)
504503

505504

506-
@pytest.mark.order(after="test_retrieve_product")
507-
def test_dp_dsl_missing(client: AtlanClient, product: DataProduct):
508-
assert product.guid
509-
test_product = (
510-
FluentSearch.select()
511-
.where(Asset.GUID.eq(product.guid))
512-
.where(Asset.TYPE_NAME.eq("DataProduct"))
513-
.to_request()
514-
)
515-
retrieved_dp = client.asset.search(test_product).current_page()[0]
516-
assert retrieved_dp
517-
assert retrieved_dp.data_product_assets_d_s_l is None # type: ignore
518-
519-
with pytest.raises(
520-
NotFoundError,
521-
match="No DataProduct Aseet DSL was found. Suggestion: You must provide a DataProduct asset DSL when retrieving DataProduct assets.",
522-
):
523-
retrieved_dp.get_assets(client) # type: ignore
524-
525-
526505
@pytest.mark.order(after="test_retrieve_contract")
527506
def test_delete_contract(client: AtlanClient, contract: DataContract):
528507
response = client.asset.purge_by_guid(contract.guid)

tests/unit/model/data_product_test.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from pyatlan.client.atlan import AtlanClient
7-
from pyatlan.errors import NotFoundError
7+
from pyatlan.errors import InvalidRequestError
88
from pyatlan.model.assets import AtlasGlossary, DataProduct
99
from pyatlan.model.enums import CertificateStatus, DataProductStatus
1010
from pyatlan.model.fluent_search import CompoundQuery, FluentSearch
@@ -23,6 +23,26 @@
2323
ASSETS_PLAYBOOK_FILTER = '{"condition":"AND","isGroupLocked":false,"rules":[]}'
2424

2525

26+
@pytest.fixture(autouse=True)
27+
def set_env(monkeypatch):
28+
monkeypatch.setenv("ATLAN_BASE_URL", "https://test.atlan.com")
29+
monkeypatch.setenv("ATLAN_API_KEY", "test-api-key")
30+
31+
32+
@pytest.fixture()
33+
def client():
34+
return AtlanClient()
35+
36+
37+
@pytest.fixture()
38+
def current_client(client, monkeypatch):
39+
monkeypatch.setattr(
40+
AtlanClient,
41+
"get_current_client",
42+
lambda: client,
43+
)
44+
45+
2646
def load_json(respones_dir, filename):
2747
with (respones_dir / filename).open() as input_file:
2848
return load(input_file)
@@ -146,17 +166,19 @@ def test_create_for_modification():
146166
_assert_product(test_product)
147167

148168

149-
def test_get_assets_with_missing_dp_asset_dsl_raise_not_found_error():
169+
def test_get_assets_with_missing_dp_asset_dsl(client: AtlanClient):
150170
data_product = DataProduct()
151-
client = AtlanClient()
152171
data_product.attributes.name = DATA_PRODUCT_NAME
153172
data_product.parent_domain_qualified_name = DATA_PRODUCT_QUALIFIED_NAME
154173
data_product.data_product_assets_d_s_l = None
155174
with pytest.raises(
156-
NotFoundError,
157-
match="No DataProduct Aseet DSL was found. Suggestion: You must provide a DataProduct asset DSL when retrieving DataProduct assets.",
175+
InvalidRequestError,
176+
match=(
177+
"Missing value for `data_product_assets_d_s_l`, "
178+
"which is required to retrieve DataProduct assets."
179+
),
158180
):
159-
data_product.get_assets(client)
181+
data_product.get_assets(client=client)
160182

161183

162184
def test_trim_to_required():

0 commit comments

Comments
 (0)