From 0d36ef2fa4911fdb34edf19573c49df648500e36 Mon Sep 17 00:00:00 2001 From: Mike Gouline <1960272+gouline@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:08:11 +1000 Subject: [PATCH] Skip columns for hidden tables (#265) --- dbtmetabase/_models.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/dbtmetabase/_models.py b/dbtmetabase/_models.py index 245e567..aed9238 100644 --- a/dbtmetabase/_models.py +++ b/dbtmetabase/_models.py @@ -100,10 +100,19 @@ def export_models( field = table.get("fields", {}).get(column_name) if not field: + if table.get("visibility_type") == "hidden": + table_label = "hidden table" + table["stale"] = True + else: + table_label = "table" + synced = False + _logger.warning( - "Field '%s' not in table '%s'", column_name, table_key + "Field '%s' not in %s '%s'", + column_name, + table_label, + table_key, ) - synced = False continue ctx.tables = tables @@ -178,6 +187,13 @@ def __export_model( model_caveats = model.caveats or None model_visibility = model.visibility_type or None + # Going from hidden to visible may require a retry + retryable = ( + api_table.get("visibility_type") == "hidden" + and model_visibility != "hidden" + and api_table.get("stale", False) + ) + body_table = {} # Update if specified, otherwise reset one that had been set @@ -205,6 +221,10 @@ def __export_model( else: _logger.info("Table '%s' is up to date", table_key) + if model_visibility == "hidden": + _logger.info("Table '%s' is hidden, skipping columns", table_key) + return success + for column in model.columns: success &= self.__export_column( ctx, @@ -221,6 +241,11 @@ def __export_model( table_key=table_key, ) + if not success and retryable: + _logger.error( + "Table '%s' got stale while hidden, retrying may help", table_key + ) + return success def __export_model_column_order(