Skip to content

Commit 1843907

Browse files
committed
Add dictionary input support for create_model methods
1 parent 8444246 commit 1843907

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sqlalchemy_crud_plus/crud.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _get_pk_filter(self, pk: Any | list[Any]) -> list[ColumnExpressionArgument[b
7070
async def create_model(
7171
self,
7272
session: AsyncSession,
73-
obj: CreateSchema,
73+
obj: CreateSchema | dict[str, Any],
7474
flush: bool = False,
7575
commit: bool = False,
7676
**kwargs,
@@ -85,7 +85,7 @@ async def create_model(
8585
:param kwargs: Additional model data not included in the pydantic schema
8686
:return:
8787
"""
88-
obj_data = obj.model_dump()
88+
obj_data = obj if isinstance(obj, dict) else obj.model_dump()
8989
if kwargs:
9090
obj_data.update(kwargs)
9191

@@ -102,7 +102,7 @@ async def create_model(
102102
async def create_models(
103103
self,
104104
session: AsyncSession,
105-
objs: list[CreateSchema],
105+
objs: list[CreateSchema | dict[str, Any]],
106106
flush: bool = False,
107107
commit: bool = False,
108108
**kwargs,
@@ -119,7 +119,7 @@ async def create_models(
119119
"""
120120
ins_list = []
121121
for obj in objs:
122-
obj_data = obj.model_dump()
122+
obj_data = obj if isinstance(obj, dict) else obj.model_dump()
123123
if kwargs:
124124
obj_data.update(kwargs)
125125
ins = self.model(**obj_data)

0 commit comments

Comments
 (0)