Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to exposures for excluding all unverified collection items #243

Merged
merged 8 commits into from
Mar 15, 2024
Merged
9 changes: 9 additions & 0 deletions dbtmetabase/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,20 @@ def models(
is_flag=True,
help="Include personal Metabase collections.",
)
@click.option(
"--exclude-unverified-cards",
envvar="EXCLUDE_UNVERIFIED_CARDS",
show_envvar=True,
is_flag=True,
help="Exclude cards that have not been verified.",
)
def exposures(
output_path: str,
output_grouping: Optional[str],
include_collections: Optional[Sequence[str]],
exclude_collections: Optional[Sequence[str]],
allow_personal_collections: bool,
exclude_unverified_cards: bool,
core: DbtMetabase,
):
core.extract_exposures(
Expand All @@ -375,6 +383,7 @@ def exposures(
exclude=exclude_collections,
),
allow_personal_collections=allow_personal_collections,
exclude_unverified_cards=exclude_unverified_cards,
)


Expand Down
9 changes: 9 additions & 0 deletions dbtmetabase/_exposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def extract_exposures(
output_grouping: Optional[str] = None,
collection_filter: Optional[Filter] = None,
allow_personal_collections: bool = False,
exclude_unverified_cards: bool = False,
) -> Iterable[Mapping]:
"""Extract dbt exposures from Metabase.

Expand All @@ -54,6 +55,7 @@ def extract_exposures(
output_grouping (Optional[str], optional): Grouping for output YAML files, supported values: "collection" (by collection slug) or "type" (by entity type). Defaults to None.
collection_filter (Optional[Filter], optional): Filter Metabase collections. Defaults to None.
allow_personal_collections (bool, optional): Allow personal Metabase collections. Defaults to False.
exclude_unverified_cards (bool, optional): Exclude unverified cards. Defaults to False.

Returns:
Iterable[Mapping]: List of parsed exposures.
Expand Down Expand Up @@ -89,6 +91,13 @@ def extract_exposures(
uid=collection["id"],
models=("card", "dashboard"),
):
if (
exclude_unverified_cards
and item.get("moderated_status") != "verified"
and item.get("model") == "card"
):
_logger.debug("Skipping unverified card '%s'", item["name"])
continue
depends = set()
native_query = ""
header = ""
Expand Down
Loading