Skip to content

Commit

Permalink
Add deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
maximearmstrong committed Jan 2, 2025
1 parent 3ab1cc2 commit c573fea
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -395,22 +396,34 @@ 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.
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c573fea

Please sign in to comment.