Skip to content

Commit

Permalink
sqlmodel: handle default_factory correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
adsharma committed Jan 19, 2025
1 parent 3c4a8a7 commit 07efaa8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fquery/sqlmodel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dataclasses
from dataclasses import _FIELD, dataclass, field, fields, is_dataclass
from datetime import date, datetime, time
from typing import (
Expand Down Expand Up @@ -99,8 +100,11 @@ def get_field_def(cls, field) -> Union[Field, Relationship]:
return Field(unique=True)

if not sql_meta or not (has_foreign_key or has_relationship):
sql_default_factory = field.default_factory
if isinstance(sql_default_factory, dataclasses._MISSING_TYPE):
sql_default_factory = None
return Field(
default_factory=getattr(cls, field.name, None),
default_factory=sql_default_factory,
# TODO: revisit the idea of using string for unknown types
sa_column=Column(
SA_TYPEMAP.get(field.type, String),
Expand Down

0 comments on commit 07efaa8

Please sign in to comment.