diff --git a/README.rst b/README.rst index 56bcb506..35c64041 100644 --- a/README.rst +++ b/README.rst @@ -170,7 +170,7 @@ Visibility Types In addition to special types, you can optionally specify visibility for each field. This affects whether or not they are displayed in the Metabase UI. -Here is how you would make that same email column hidden: +Here is how you would hide that same email: .. code-block:: yaml @@ -179,15 +179,15 @@ Here is how you would make that same email column hidden: tests: - metabase.field: special_type: type/Email - visibility_type: hidden + visibility_type: sensitive Here are the visibility types supported by Metabase: * ``normal`` (default) * ``details-only`` -* ``hidden`` -* ``retired`` * ``sensitive`` +* ``hidden`` (supported but not reflected in the UI) +* ``retired`` (supported but not reflected in the UI) If you notice new ones, please submit a PR to update this readme and ``macros/tests.sql``. diff --git a/dbtmetabase/__init__.py b/dbtmetabase/__init__.py index ac99269f..7352005a 100644 --- a/dbtmetabase/__init__.py +++ b/dbtmetabase/__init__.py @@ -3,7 +3,7 @@ from .dbt import DbtReader from .metabase import MetabaseClient -__version__ = '0.2.0' +__version__ = '0.2.1' def export(dbt_path: str, mb_host: str, mb_user: str, mb_password: str, diff --git a/dbtmetabase/metabase.py b/dbtmetabase/metabase.py index f912a499..608370f5 100644 --- a/dbtmetabase/metabase.py +++ b/dbtmetabase/metabase.py @@ -182,15 +182,20 @@ def export_column(self, model_name: str, column: dict, field_lookup: dict): self.api('put', f'/api/field/{fk_target_field_id}', json={ 'special_type': 'type/PK' }) + + # Nones are not accepted, default to normal + if not column.get('visibility_type'): + column['visibility_type'] = 'normal' api_field = self.api('get', f'/api/field/{field_id}') if api_field['description'] != column.get('description') or \ api_field['special_type'] != column.get('special_type') or \ + api_field['visibility_type'] != column.get('visibility_type') or \ api_field['fk_target_field_id'] != fk_target_field_id: - api_field['description'] = self.sanitize_macro_field(column.get('description')) - api_field['special_type'] = self.sanitize_macro_field(column.get('special_type')) - api_field['visibility_type'] = self.sanitize_macro_field(column.get('visibility_type')) + api_field['description'] = column.get('description') + api_field['special_type'] = column.get('special_type') + api_field['visibility_type'] = column.get('visibility_type') api_field['fk_target_field_id'] = fk_target_field_id self.api('put', f'/api/field/{field_id}', json=api_field) @@ -294,18 +299,3 @@ def api(self, method: str, path: str, authenticated = True, critical = True, **k elif not response.ok: return False return json.loads(response.text) - - @staticmethod - def sanitize_macro_field(value: str) -> Any: - """Sanitizes macro field values for possible empty strings. - - Arguments: - value {str} -- String, could be empty or none. - - Returns: - Any -- Either none or non-empty string. - """ - - if not value: - return None - return value