Skip to content

Commit

Permalink
update models modules
Browse files Browse the repository at this point in the history
  • Loading branch information
matanmichaely committed Sep 19, 2024
1 parent a286f69 commit 08efc20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 18 additions & 4 deletions yoda_dbt2looker/core/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Dict, List, Optional, Union
from typing import Dict, List, Optional, Union, Any

try:
from typing import Literal
except ImportError:
from typing_extensions import Literal
from pydantic import Field, validator, BaseModel
from pydantic import Field, field_validator, BaseModel, ValidationError, model_validator

from yoda_dbt2looker.models import (
DbtNode,
Expand Down Expand Up @@ -34,7 +34,7 @@ class DbtModel(DbtNode):
meta: DbtModelMeta
config: DbtModelConfig

@validator("columns")
@field_validator("columns")
def case_insensitive_column_names(cls, v: Dict[str, DbtModelColumn]):
return {
name.lower(): column.copy(update={"name": column.name.lower()})
Expand All @@ -43,5 +43,19 @@ def case_insensitive_column_names(cls, v: Dict[str, DbtModelColumn]):


class DbtManifest(BaseModel):
nodes: Dict[str, Union[DbtModel, DbtNode]]
# TODO: check why Union doesn't work
nodes: Dict[str, Any]
metadata: DbtManifestMetadata

@model_validator(mode="before")
def validate_nodes_and_exposures(cls, values):
nodes = values.get('nodes', {})
# Validate 'nodes' field
validated_nodes = {}
for key, value in nodes.items():
try:
validated_nodes[key] = DbtModel(**value)
except ValidationError as e:
validated_nodes[key] = DbtNode(**value)
values['nodes'] = validated_nodes
return values
2 changes: 0 additions & 2 deletions yoda_dbt2looker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@ def validate_nodes_and_exposures(cls, values):
try:
validated_nodes[key] = DbtModel(**value)
except ValidationError as e:
if "model.yoda.yoda_e2e_loyalty__fact_store_profile_daily" == key:
print(f"failed to parse {key} , errors: {e.errors()}")
validated_nodes[key] = DbtNode(**value)

# Validate 'exposures' field
Expand Down

0 comments on commit 08efc20

Please sign in to comment.