From fcf91cfd3cd751570be166520e011aa0893bc36e Mon Sep 17 00:00:00 2001 From: Mike Gouline <1960272+gouline@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:29:08 +1100 Subject: [PATCH] Fix type and format issues --- dbtmetabase/_exposures.py | 12 +++++++----- dbtmetabase/metabase.py | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/dbtmetabase/_exposures.py b/dbtmetabase/_exposures.py index ce29120..35b95e9 100644 --- a/dbtmetabase/_exposures.py +++ b/dbtmetabase/_exposures.py @@ -95,11 +95,12 @@ def extract_exposures( entity: Mapping if item["model"] == "card": - entity = self.metabase.find_card(uid=item["id"]) - if entity is None: + card_entity = self.metabase.find_card(uid=item["id"]) + if card_entity is None: _logger.info("Card '%s' not found, skipping", item["id"]) continue + entity = card_entity header = ( f"Visualization: {entity.get('display', 'Unknown').title()}" ) @@ -109,11 +110,12 @@ def extract_exposures( native_query = result["native_query"] elif item["model"] == "dashboard": - entity = self.metabase.find_dashboard(uid=item["id"]) - if entity is None: + dashboard_entity = self.metabase.find_dashboard(uid=item["id"]) + if dashboard_entity is None: _logger.info("Dashboard '%s' not found, skipping", item["id"]) continue + entity = dashboard_entity cards = entity.get("ordered_cards", []) if not cards: continue @@ -185,7 +187,7 @@ def extract_exposures( def __extract_card_exposures( self, ctx: __Context, - card: Mapping, + card: Optional[Mapping], ) -> Mapping: """Extracts exposures from Metabase questions.""" diff --git a/dbtmetabase/metabase.py b/dbtmetabase/metabase.py index 5e66de9..367bec2 100644 --- a/dbtmetabase/metabase.py +++ b/dbtmetabase/metabase.py @@ -167,10 +167,6 @@ def find_dashboard(self, uid: str) -> Optional[Mapping]: return None raise - def format_dashboard_url(self, uid: str) -> str: - """Formats URL link to a dashboard.""" - return f"{self.url}/dashboard/{uid}" - def find_user(self, uid: str) -> Optional[Mapping]: """Finds user by ID or returns none.""" try: @@ -181,6 +177,10 @@ def find_user(self, uid: str) -> Optional[Mapping]: return None raise + def format_dashboard_url(self, uid: str) -> str: + """Formats URL link to a dashboard.""" + return f"{self.url}/dashboard/{uid}" + def update_table(self, uid: str, body: Mapping) -> Mapping: """Posts update to an existing table.""" return dict(self._api("put", f"/api/table/{uid}", json=body))