Skip to content

Commit

Permalink
missing model_config populate_by_name
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Oct 17, 2024
1 parent 75d1fb8 commit 7ac8043
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion edgedb_pydantic_codegen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def parse_type(
case _:
type_str = f"Sequence[{element_type_str}]"

case _: # TODO: TupleType, RangeType, MultiRangeType
case _: # TODO: TupleType, RangeType, MultiRangeType
raise ValueError(f"Unsupported type: {type}")

return type_str
Expand Down Expand Up @@ -268,6 +268,7 @@ def parse_model(
del fields["id"]

new_model.fields = list(fields.values())
new_model.has_aliased_fields = any(f.alias for f in new_model.fields)

return new_model

Expand Down
1 change: 1 addition & 0 deletions edgedb_pydantic_codegen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class EdgeQLNamedTupleField:
class EdgeQLModel:
name: str
fields: list["EdgeQLModelField"] = dc_field(default_factory=list)
has_aliased_fields: bool = False


@dataclass
Expand Down
5 changes: 4 additions & 1 deletion edgedb_pydantic_codegen/template.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from uuid import UUID

import orjson
from edgedb import AsyncIOExecutor
from pydantic import BaseModel, Field, TypeAdapter
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter

EDGEQL_QUERY = r"""
{{query}}
Expand Down Expand Up @@ -37,6 +37,9 @@ class {{ntuple.name}}(NamedTuple):

{% for model in models | reverse %}
class {{model.name}}(BaseModel):
{% if model.has_aliased_fields -%}
model_config = ConfigDict(populate_by_name=True)
{%- endif %}
{% for field in model.fields -%}
{{field.name}}:
{%- if field.optional -%}
Expand Down

0 comments on commit 7ac8043

Please sign in to comment.