Skip to content

Commit

Permalink
Add flag to exposures for excluding all unverified collection items (#…
Browse files Browse the repository at this point in the history
…243)

* add flag to exclude unverified collection items

* simplify check for moderation status

* leave dashboards alone

* Add

Co-authored-by: Mike Gouline <1960272+gouline@users.noreply.github.com>

* Revise ordering of exclusion logic

Co-authored-by: Mike Gouline <1960272+gouline@users.noreply.github.com>

* revert flag name now that we have alignment

---------

Co-authored-by: Mike Gouline <1960272+gouline@users.noreply.github.com>
  • Loading branch information
alex-float-on and gouline committed Mar 15, 2024
1 parent f8e803a commit 7803ae2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit 7803ae2

Please sign in to comment.