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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
envvar="EXCLUDE_UNVERIFIED",
show_envvar=True,
is_flag=True,
help="Exclude items that have not been verified. Only applies to entity types that support verification.",
)
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: 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=exclude_unverified,
)


Expand Down
10 changes: 10 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: 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 (bool, optional): Exclude items that have not been verified. Only applies to entity types that support verification. Defaults to False.

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

depends = set()
native_query = ""
header = ""
Expand Down
Loading