diff --git a/examples/docs_snippets/docs_snippets/integrations/power-bi/customize-power-bi-asset-defs.py b/examples/docs_snippets/docs_snippets/integrations/power-bi/customize-power-bi-asset-defs.py index a20163dd0e82b..d7b49b6141642 100644 --- a/examples/docs_snippets/docs_snippets/integrations/power-bi/customize-power-bi-asset-defs.py +++ b/examples/docs_snippets/docs_snippets/integrations/power-bi/customize-power-bi-asset-defs.py @@ -38,7 +38,7 @@ def get_asset_spec(self, data: PowerBIContentData) -> dg.AssetSpec: power_bi_specs = load_powerbi_asset_specs( power_bi_workspace, - dagster_powerbi_translator=MyCustomPowerBITranslator, # type: ignore + dagster_powerbi_translator=MyCustomPowerBITranslator, ) defs = dg.Definitions( assets=[*power_bi_specs], resources={"power_bi": power_bi_workspace} diff --git a/python_modules/libraries/dagster-powerbi/dagster_powerbi/resource.py b/python_modules/libraries/dagster-powerbi/dagster_powerbi/resource.py index 473b6fb0de6ab..8d17944df9b4c 100644 --- a/python_modules/libraries/dagster-powerbi/dagster_powerbi/resource.py +++ b/python_modules/libraries/dagster-powerbi/dagster_powerbi/resource.py @@ -4,7 +4,7 @@ import time from dataclasses import dataclass from functools import cached_property -from typing import Any, Dict, Mapping, Optional, Sequence, Type +from typing import Any, Dict, Mapping, Optional, Sequence, Type, Union from urllib.parse import urlencode import requests @@ -21,6 +21,7 @@ from dagster._time import get_current_timestamp from dagster._utils.cached_method import cached_method from dagster._utils.security import non_secure_md5_hash_str +from dagster._utils.warnings import deprecation_warning from pydantic import Field, PrivateAttr from dagster_powerbi.translator import ( @@ -395,15 +396,17 @@ def build_defs( @experimental def load_powerbi_asset_specs( workspace: PowerBIWorkspace, - dagster_powerbi_translator: Optional[DagsterPowerBITranslator] = None, + dagster_powerbi_translator: Optional[ + Union[DagsterPowerBITranslator, Type[DagsterPowerBITranslator]] + ] = None, use_workspace_scan: bool = True, ) -> Sequence[AssetSpec]: """Returns a list of AssetSpecs representing the Power BI content in the workspace. Args: workspace (PowerBIWorkspace): The Power BI workspace to load assets from. - dagster_powerbi_translator (Optional[DagsterPowerBITranslator]): The translator to use - to convert Power BI content into :py:class:`dagster.AssetSpec`. + dagster_powerbi_translator (Optional[Union[DagsterPowerBITranslator, Type[DagsterPowerBITranslator]]]): + The translator to use to convert Power BI content into :py:class:`dagster.AssetSpec`. Defaults to :py:class:`DagsterPowerBITranslator`. use_workspace_scan (bool): Whether to scan the entire workspace using admin APIs at once to get all content. Defaults to True. @@ -411,6 +414,16 @@ def load_powerbi_asset_specs( Returns: List[AssetSpec]: The set of assets representing the Power BI content in the workspace. """ + if isinstance(dagster_powerbi_translator, type): + deprecation_warning( + subject="Support of `dagster_powerbi_translator` as a Type[DagsterPowerBITranslator]", + breaking_version="1.10", + additional_warn_text=( + "Pass an instance of DagsterPowerBITranslator or subclass to `dagster_powerbi_translator` instead." + ), + ) + dagster_powerbi_translator = dagster_powerbi_translator() + with workspace.process_config_and_initialize_cm() as initialized_workspace: return check.is_list( PowerBIWorkspaceDefsLoader( diff --git a/python_modules/libraries/dagster-powerbi/dagster_powerbi_tests/test_asset_specs.py b/python_modules/libraries/dagster-powerbi/dagster_powerbi_tests/test_asset_specs.py index 32196a361cebd..5f5547184a1b1 100644 --- a/python_modules/libraries/dagster-powerbi/dagster_powerbi_tests/test_asset_specs.py +++ b/python_modules/libraries/dagster-powerbi/dagster_powerbi_tests/test_asset_specs.py @@ -111,6 +111,27 @@ def test_translator_custom_metadata(workspace_data_api_mocks: None, workspace_id assert "dagster/kind/powerbi" in asset_spec.tags +def test_translator_custom_metadata_legacy( + workspace_data_api_mocks: None, workspace_id: str +) -> None: + fake_token = uuid.uuid4().hex + resource = PowerBIWorkspace( + credentials=PowerBIToken(api_token=fake_token), + workspace_id=workspace_id, + ) + all_asset_specs = load_powerbi_asset_specs( + workspace=resource, + dagster_powerbi_translator=MyCustomTranslator, + use_workspace_scan=False, + ) + asset_spec = next(spec for spec in all_asset_specs) + + assert "custom" in asset_spec.metadata + assert asset_spec.metadata["custom"] == "metadata" + assert asset_spec.key.path == ["prefix", "dashboard", "Sales_Returns_Sample_v201912"] + assert "dagster/kind/powerbi" in asset_spec.tags + + @lazy_definitions def state_derived_defs_two_workspaces() -> Definitions: resource = PowerBIWorkspace(