Skip to content

Commit 70b8f1d

Browse files
committed
[generator] Fixed circular imports due to Process related to SQL assets
1 parent 1a4f12b commit 70b8f1d

4 files changed

Lines changed: 46 additions & 36 deletions

File tree

pyatlan/generator/class_generator.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,15 @@ class AssetInfo:
223223
entity_defs_by_name: Dict[str, EntityDef] = {}
224224
sub_type_names_to_ignore: Set[str] = set()
225225
is_core_asset: bool = False
226-
_ASSETS_REQUIRE_CLIENT = {
226+
_ASSETS_REQUIRE_TYPE_CHECKING = {
227227
"Badge",
228228
"Collection",
229229
"Connection",
230230
"DataProduct",
231231
"Referenceable",
232232
"Purpose",
233233
"DataQualityRule",
234+
"Process",
234235
}
235236
_ASSETS_REQUIRE_ASYNC_CLIENT = {
236237
"Badge",
@@ -253,7 +254,20 @@ class AssetInfo:
253254
"DocumentDBCollection",
254255
"FlowDataset",
255256
"DatabricksAIModelVersion",
257+
"Fabric",
258+
"FabricDashboard",
259+
"FabricDataflow",
260+
"FabricActivity",
261+
"FabricPage",
262+
"FabricWorkspace",
263+
"FabricDataPipeline",
264+
"FabricSemanticModelTable",
265+
"FabricSemanticModelTableColumn",
266+
"FabricDataflowEntityColumn",
267+
"FabricReport",
268+
"FabricSemanticModel",
256269
}
270+
_IGNORE_ASSETS = {}
257271

258272
def __init__(self, name: str, entity_def: EntityDef):
259273
self._name = name
@@ -304,6 +318,19 @@ def imports_for_referenced_assets(self):
304318
imports = []
305319

306320
for required_asset in self.required_asset_infos:
321+
# To avoid circular import issues with DataQualityRule and Column
322+
# Though we import Column in data_quality_rule.py for type hinting purposes,
323+
if self.name == "DataQualityRule" and required_asset.name == "Column":
324+
continue
325+
# FIXME: Temporary fix to avoid circular import issues
326+
# Process cant have relationship to Procedure,
327+
# BigqueryRoutine, FabricActivity since its a super type is SQL
328+
if self.name == "Process" and required_asset.name in (
329+
"Procedure",
330+
"BigqueryRoutine",
331+
"FabricActivity",
332+
):
333+
continue
307334
if not self.is_core_asset and required_asset.is_core_asset:
308335
import_statement = f"from .core.{required_asset.module_name} import {required_asset.name} # noqa: E402, F401"
309336
else:
@@ -357,6 +384,8 @@ def update_required_asset_names(self) -> None:
357384
relationship_attribute_defs = self.entity_def.relationship_attribute_defs or []
358385
for attribute in attribute_defs + relationship_attribute_defs:
359386
type_name = attribute["typeName"].replace("array<", "").replace(">", "")
387+
# if type_name in AssetInfo._IGNORE_ASSETS:
388+
# continue
360389
if type_name == self._name:
361390
continue
362391
if type_name in AssetInfo.super_type_names_to_ignore:
@@ -438,6 +467,9 @@ def create_modules(cls):
438467
cls.hierarchy_graph, REFERENCEABLE
439468
):
440469
for asset_name in [parent_name] + successors:
470+
# if asset_name in cls._IGNORE_ASSETS:
471+
# print(f"Ignoring asset {asset_name}")
472+
# continue
441473
asset_info = cls.asset_info_by_name[asset_name]
442474
asset_info.order = order
443475
order += 1

pyatlan/generator/templates/imports.jinja2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ from pyatlan.model.structs import (
118118
DatabricksAIModelVersionMetric,
119119
AssetHistogram,
120120
AppWorkflowRunStep,
121+
SQLProcedureReturn,
122+
SQLProcedureArgument,
123+
AssetExternalDQMetadata,
124+
AssetGCPDataplexMetadata,
125+
AssetGCPDataplexAspectMetadata,
126+
AssetExternalDQTestRunHistory,
121127
)
122128
from pyatlan.utils import (
123129
init_guid,

pyatlan/generator/templates/module.jinja2

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

77
{% include 'imports.jinja2' %}
88

9-
{% if asset_info.name not in asset_info._ASSETS_REQUIRE_CLIENT %}
9+
{% if asset_info.name not in asset_info._ASSETS_REQUIRE_TYPE_CHECKING %}
1010
from pyatlan.client.atlan import AtlanClient
1111
{% endif %}
1212

@@ -37,12 +37,17 @@ from .process import Process
3737

3838
{{ asset_info.import_super_class }}
3939

40-
{% if asset_info.name in asset_info._ASSETS_REQUIRE_CLIENT %}
40+
{% if asset_info.name in asset_info._ASSETS_REQUIRE_TYPE_CHECKING %}
4141
if TYPE_CHECKING:
4242
from pyatlan.client.atlan import AtlanClient
4343
{% if asset_info.name == 'DataQualityRule' %}
4444
from pyatlan.model.assets import Column
4545
{% endif %}
46+
{% if asset_info.name == 'Process' %}
47+
from pyatlan.model.assets import Procedure
48+
from pyatlan.model.assets import BigqueryRoutine
49+
from pyatlan.model.assets import FabricActivity
50+
{% endif %}
4651
{% if asset_info.name in asset_info._ASSETS_REQUIRE_ASYNC_CLIENT %}
4752
from pyatlan.client.aio.client import AsyncAtlanClient
4853
from pyatlan.model.aio import AsyncCustomMetadataProxy

pyatlan/model/assets/databricks.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)