From 7803ae273426e98e5583b0aa87a85554e5a499f4 Mon Sep 17 00:00:00 2001 From: alex-float-on <159055527+alex-float-on@users.noreply.github.com> Date: Fri, 15 Mar 2024 01:01:24 -0400 Subject: [PATCH] Add flag to exposures for excluding all unverified collection items (#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> --- dbtmetabase/__main__.py | 9 +++++++++ dbtmetabase/_exposures.py | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/dbtmetabase/__main__.py b/dbtmetabase/__main__.py index e225d9a2..779c5c5f 100644 --- a/dbtmetabase/__main__.py +++ b/dbtmetabase/__main__.py @@ -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( @@ -375,6 +383,7 @@ def exposures( exclude=exclude_collections, ), allow_personal_collections=allow_personal_collections, + exclude_unverified=exclude_unverified, ) diff --git a/dbtmetabase/_exposures.py b/dbtmetabase/_exposures.py index 7b3783b8..b4cac4c4 100644 --- a/dbtmetabase/_exposures.py +++ b/dbtmetabase/_exposures.py @@ -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. @@ -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. @@ -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 = ""