Skip to content

Commit

Permalink
Fixes for visibility_type
Browse files Browse the repository at this point in the history
  • Loading branch information
gouline committed Feb 24, 2020
1 parent b26877e commit 9d17081
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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``.
Expand Down
2 changes: 1 addition & 1 deletion dbtmetabase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 8 additions & 18 deletions dbtmetabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 9d17081

Please sign in to comment.