From 349c8ff0b929339c6d8f64d75200ca857413aa1a Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Wed, 25 Oct 2023 10:25:36 -0700 Subject: [PATCH] Update to use aliasing that works for pydantic 1.10 --- dbt_semantic_interfaces/implementations/export.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dbt_semantic_interfaces/implementations/export.py b/dbt_semantic_interfaces/implementations/export.py index d9d1e6f7..386a759e 100644 --- a/dbt_semantic_interfaces/implementations/export.py +++ b/dbt_semantic_interfaces/implementations/export.py @@ -16,16 +16,20 @@ class PydanticExportConfig(HashableBaseModel, ProtocolHint[ExportConfig]): """Pydantic implementation of ExportConfig. - Note on `schema_name`: `schema` is a BaseModel attribute so we need to alias it here. - Use `schema` for YAML definition & JSON, `schema_name` for object attribute. + Note on `schema_name`: `schema` is an existing BaseModel attribute, so we need to alias it here. + `Field.alias="schema"` enables using the `schema` key in YAML. `Config.allow_population_by_field_name` + enables parsing for both `schema` and `schema_name` when deserializing from JSON. """ + class Config: + allow_population_by_field_name = True + @override def _implements_protocol(self) -> ExportConfig: return self export_as: ExportDestinationType - schema_name: Optional[str] = Field(serialization_alias="schema", validation_alias="schema_name") + schema_name: Optional[str] = Field(alias="schema", default=None) alias: Optional[str] = None