diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d77bc..a94c873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ Recent and upcoming changes to dbt2looker +## 0.9.1 +### Fixed +- Fixed bug where dbt2looker would crash if a dbt project contained an empty model + +### Changed +- When filtering models by tag, models that have no tag property will be ignored + ## 0.9.0 ### Added - Support for spark adapter (@chaimt) diff --git a/dbt2looker/parser.py b/dbt2looker/parser.py index 588e93a..1f7a229 100644 --- a/dbt2looker/parser.py +++ b/dbt2looker/parser.py @@ -2,7 +2,7 @@ import json import jsonschema import importlib.resources -from typing import Dict, Optional, List +from typing import Dict, Optional, List, Union from functools import reduce from . import models @@ -46,6 +46,16 @@ def parse_adapter_type(raw_manifest: dict): return manifest.metadata.adapter_type +def tags_match(query_tag: str, model: models.DbtModel) -> bool: + try: + return query_tag in model.tags + except AttributeError: + return False + except ValueError: + # Is the tag just a string? + return query_tag == model.tags + + def parse_models(raw_manifest: dict, tag=None) -> List[models.DbtModel]: manifest = models.DbtManifest(**raw_manifest) all_models: List[models.DbtModel] = [ @@ -53,13 +63,16 @@ def parse_models(raw_manifest: dict, tag=None) -> List[models.DbtModel]: for node in manifest.nodes.values() if node.resource_type == 'model' ] - filtered_models = ( - all_models if tag is None else [ - model for model in all_models - if tag in model.tags - ] - ) - return filtered_models + + # Empty model files have many missing parameters + for model in all_models: + if not hasattr(model, 'name'): + logging.error('Cannot parse model with id: "%s" - is the model file empty?', model.unique_id) + raise SystemExit('Failed') + + if tag is None: + return all_models + return [model for model in all_models if tags_match(tag, model)] def check_models_for_missing_column_types(dbt_typed_models: List[models.DbtModel]): diff --git a/poetry.lock b/poetry.lock index d62c1fc..9d37764 100644 --- a/poetry.lock +++ b/poetry.lock @@ -104,7 +104,7 @@ python-versions = "*" [[package]] name = "zipp" -version = "3.5.0" +version = "3.6.0" description = "Backport of pathlib-compatible object wrapper for zip files" category = "main" optional = false @@ -224,6 +224,6 @@ typing-extensions = [ {file = "typing_extensions-3.10.0.2.tar.gz", hash = "sha256:49f75d16ff11f1cd258e1b988ccff82a3ca5570217d7ad8c5f48205dd99a677e"}, ] zipp = [ - {file = "zipp-3.5.0-py3-none-any.whl", hash = "sha256:957cfda87797e389580cb8b9e3870841ca991e2125350677b2ca83a0e99390a3"}, - {file = "zipp-3.5.0.tar.gz", hash = "sha256:f5812b1e007e48cff63449a5e9f4e7ebea716b4111f9c4f9a645f91d579bf0c4"}, + {file = "zipp-3.6.0-py3-none-any.whl", hash = "sha256:9fe5ea21568a0a70e50f273397638d39b03353731e6cbbb3fd8502a33fec40bc"}, + {file = "zipp-3.6.0.tar.gz", hash = "sha256:71c644c5369f4a6e07636f0aa966270449561fcea2e3d6747b8d23efaa9d7832"}, ] diff --git a/pyproject.toml b/pyproject.toml index a486fa9..c5aad33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dbt2looker" -version = "0.9.0" +version = "0.9.1" description = "Generate lookml view files from dbt models" authors = ["oliverlaslett "] license = "MIT"