Skip to content

Commit

Permalink
Migrate to pydantic v2 (lightdash#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddyAlton committed Oct 7, 2024
1 parent 8c5a2c3 commit 51dbdfb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Recent and upcoming changes to dbt2looker
### Changed
- only non-ephemeral models _selected by tag logic_ are checked to ensure the model files are not empty (instead of all models) (#57)

### Fixed
- now supports `pydantic` v2 (#97)

## 0.11.0
### Added
- support label and hidden fields (#49)
Expand Down
37 changes: 19 additions & 18 deletions dbt2looker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from typing import Literal
except ImportError:
from typing_extensions import Literal
from pydantic import BaseModel, Field, PydanticValueError, validator
from pydantic import BaseModel, Field, validator


# dbt2looker utility types
class UnsupportedDbtAdapterError(PydanticValueError):
code = 'unsupported_dbt_adapter'
msg_template = '{wrong_value} is not a supported dbt adapter'
class UnsupportedDbtAdapterError(ValueError):
def __init__(self, wrong_value: str):
msg = f'{wrong_value} is not a supported dbt adapter'
super().__init__(msg)


class SupportedDbtAdapters(str, Enum):
Expand Down Expand Up @@ -82,12 +83,12 @@ class LookerHiddenType(str, Enum):
class Dbt2LookerMeasure(BaseModel):
type: LookerMeasureType
filters: Optional[List[Dict[str, str]]] = []
description: Optional[str]
sql: Optional[str]
value_format_name: Optional[LookerValueFormatName]
group_label: Optional[str]
label: Optional[str]
hidden: Optional[LookerHiddenType]
description: Optional[str] = None
sql: Optional[str] = None
value_format_name: Optional[LookerValueFormatName] = None
group_label: Optional[str] = None
label: Optional[str] = None
hidden: Optional[LookerHiddenType] = None

@validator('filters')
def filters_are_singular_dicts(cls, v: List[Dict[str, str]]):
Expand All @@ -100,10 +101,10 @@ def filters_are_singular_dicts(cls, v: List[Dict[str, str]]):

class Dbt2LookerDimension(BaseModel):
enabled: Optional[bool] = True
name: Optional[str]
sql: Optional[str]
description: Optional[str]
value_format_name: Optional[LookerValueFormatName]
name: Optional[str] = None
sql: Optional[str] = None
description: Optional[str] = None
value_format_name: Optional[LookerValueFormatName] = None


class Dbt2LookerMeta(BaseModel):
Expand Down Expand Up @@ -137,7 +138,7 @@ class DbtModelColumnMeta(Dbt2LookerMeta):
class DbtModelColumn(BaseModel):
name: str
description: str
data_type: Optional[str]
data_type: Optional[str] = None
meta: DbtModelColumnMeta


Expand Down Expand Up @@ -201,13 +202,13 @@ class DbtCatalogNodeMetadata(BaseModel):
type: str
db_schema: str = Field(..., alias='schema')
name: str
comment: Optional[str]
owner: Optional[str]
comment: Optional[str] = None
owner: Optional[str] = None


class DbtCatalogNodeColumn(BaseModel):
type: str
comment: Optional[str]
comment: Optional[str] = None
index: int
name: str

Expand Down

0 comments on commit 51dbdfb

Please sign in to comment.