From 23f3477ec9eea5f404a0c162dc6610cde607675d Mon Sep 17 00:00:00 2001 From: Sultan Iman Date: Mon, 29 Jan 2024 16:54:47 +0100 Subject: [PATCH] Use snake_case naming convention to generate field names --- dlt/common/libs/pydantic.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dlt/common/libs/pydantic.py b/dlt/common/libs/pydantic.py index 4c536fc68e..7273a073de 100644 --- a/dlt/common/libs/pydantic.py +++ b/dlt/common/libs/pydantic.py @@ -14,10 +14,11 @@ ) from typing_extensions import Annotated, get_args, get_origin +from dlt.common.data_types import py_type_to_sc_type from dlt.common.exceptions import MissingDependencyException from dlt.common.schema import DataValidationError from dlt.common.schema.typing import TSchemaEvolutionMode, TTableSchemaColumns -from dlt.common.data_types import py_type_to_sc_type +from dlt.common.normalizers.naming.snake_case import NamingConvention as SnakeCaseNamingConvention from dlt.common.typing import ( TDataItem, TDataItems, @@ -52,6 +53,9 @@ _TPydanticModel = TypeVar("_TPydanticModel", bound=BaseModel) +snake_case_naming_convention = SnakeCaseNamingConvention() + + class ListModel(BaseModel, Generic[_TPydanticModel]): items: List[_TPydanticModel] @@ -131,11 +135,12 @@ def pydantic_to_table_schema_columns( if is_inner_type_pydantic_model: schema_hints = pydantic_to_table_schema_columns(field.annotation) - def patch_child(parent_field_name: str, hints: dict) -> dict: - return {**hints, "name": f"{parent_field_name}__{hints['name']}"} - for field_name, hints in schema_hints.items(): - result[f"{name}__{field_name}"] = patch_child(name, hints) + schema_key = snake_case_naming_convention.make_path(name, field_name) + result[schema_key] = { + **hints, + "name": snake_case_naming_convention.make_path(name, hints["name"]), + } else: result[name] = { "name": name,