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 2f58f9e commit ec0c8f1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def get_asset_spec(self, data: TableauContentData) -> dg.AssetSpec:

tableau_specs = load_tableau_asset_specs(
tableau_workspace,
dagster_tableau_translator=MyCustomTableauTranslator, # type: ignore
dagster_tableau_translator=MyCustomTableauTranslator,
)
defs = dg.Definitions(assets=[*tableau_specs], resources={"tableau": tableau_workspace})
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from dagster._core.definitions.definitions_load_context import StateBackedDefinitionsLoader
from dagster._record import record
from dagster._utils.cached_method import cached_method
from dagster._utils.warnings import deprecation_warning
from pydantic import Field, PrivateAttr
from tableauserverclient.server.endpoint.auth_endpoint import Auth

Expand Down Expand Up @@ -533,19 +534,31 @@ def build_defs(
@experimental
def load_tableau_asset_specs(
workspace: BaseTableauWorkspace,
dagster_tableau_translator: Optional[DagsterTableauTranslator] = None,
dagster_tableau_translator: Optional[
Union[DagsterTableauTranslator, Type[DagsterTableauTranslator]]
] = None,
) -> Sequence[AssetSpec]:
"""Returns a list of AssetSpecs representing the Tableau content in the workspace.
Args:
workspace (Union[TableauCloudWorkspace, TableauServerWorkspace]): The Tableau workspace to fetch assets from.
dagster_tableau_translator (Optional[DagsterTableauTranslator]): The translator to use
to convert Tableau content into :py:class:`dagster.AssetSpec`.
dagster_tableau_translator (Optional[Union[DagsterTableauTranslator, Type[DagsterTableauTranslator]]]):
The translator to use to convert Tableau content into :py:class:`dagster.AssetSpec`.
Defaults to :py:class:`DagsterTableauTranslator`.
Returns:
List[AssetSpec]: The set of assets representing the Tableau content in the workspace.
"""
if isinstance(dagster_tableau_translator, type):
deprecation_warning(
subject="Support of `dagster_tableau_translator` as a Type[DagsterTableauTranslator]",
breaking_version="1.10",
additional_warn_text=(
"Pass an instance of DagsterTableauTranslator or subclass to `dagster_tableau_translator` instead."
),
)
dagster_tableau_translator = dagster_tableau_translator()

with workspace.process_config_and_initialize_cm() as initialized_workspace:
return check.is_list(
TableauWorkspaceDefsLoader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,54 @@ def test_translator_custom_metadata(
assert asset_spec.metadata["custom"] == "metadata"
assert asset_spec.key.path == ["prefix", "superstore_datasource"]
assert asset_spec.tags["dagster/storage_kind"] == "tableau"


@responses.activate
@pytest.mark.parametrize(
"clazz,host_key,host_value",
[
(TableauServerWorkspace, "server_name", "fake_server_name"),
(TableauCloudWorkspace, "pod_name", "fake_pod_name"),
],
)
@pytest.mark.usefixtures("site_name")
@pytest.mark.usefixtures("sign_in")
@pytest.mark.usefixtures("get_workbooks")
@pytest.mark.usefixtures("get_workbook")
def test_translator_custom_metadata_legacy(
clazz: Union[Type[TableauCloudWorkspace], Type[TableauServerWorkspace]],
host_key: str,
host_value: str,
site_name: str,
sign_in: MagicMock,
get_workbooks: MagicMock,
get_workbook: MagicMock,
) -> None:
connected_app_client_id = uuid.uuid4().hex
connected_app_secret_id = uuid.uuid4().hex
connected_app_secret_value = uuid.uuid4().hex
username = "fake_username"

with environ({"TABLEAU_CLIENT_ID": connected_app_client_id}):
resource_args = {
"connected_app_client_id": EnvVar("TABLEAU_CLIENT_ID"),
"connected_app_secret_id": connected_app_secret_id,
"connected_app_secret_value": connected_app_secret_value,
"username": username,
"site_name": site_name,
host_key: host_value,
}

resource = clazz(**resource_args)
resource.build_client()

# Pass the translator type
all_asset_specs = load_tableau_asset_specs(
workspace=resource, dagster_tableau_translator=MyCustomTranslator
)
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", "superstore_datasource"]
assert asset_spec.tags["dagster/storage_kind"] == "tableau"
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ def get_asset_spec(self, data: TableauTranslatorData) -> AssetSpec:
return Definitions(assets=[*tableau_specs], jobs=[define_asset_job("all_asset_job")])


@lazy_definitions
def cacheable_asset_defs_custom_translator_legacy():
class MyCoolTranslator(DagsterTableauTranslator):
def get_asset_spec(self, data: TableauTranslatorData) -> AssetSpec:
default_spec = super().get_asset_spec(data)
return default_spec.replace_attributes(key=default_spec.key.with_prefix("my_prefix"))

# Pass the translator type
tableau_specs = load_tableau_asset_specs(
workspace=resource, dagster_tableau_translator=MyCoolTranslator
)

return Definitions(assets=[*tableau_specs], jobs=[define_asset_job("all_asset_job")])


def test_load_assets_workspace_data_refreshable_workbooks(
sign_in: MagicMock,
get_workbooks: MagicMock,
Expand Down

0 comments on commit ec0c8f1

Please sign in to comment.