Skip to content

Commit 37e92bf

Browse files
committed
fix get_multi typing when return_as_model is True
1 parent e76ddba commit 37e92bf

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

fastcrud/crud/fast_crud.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
SelectSchemaType,
3333
UpdateSchemaInternalType,
3434
UpdateSchemaType,
35+
GetMultiResponseModel,
36+
GetMultiResponseDict,
3537
)
3638

3739
from .helper import (
@@ -1148,7 +1150,7 @@ async def get_multi(
11481150
return_as_model: bool = False,
11491151
return_total_count: bool = True,
11501152
**kwargs: Any,
1151-
) -> dict[str, Any]:
1153+
) -> Union[GetMultiResponseModel[SelectSchemaType], GetMultiResponseDict]:
11521154
"""
11531155
Fetches multiple records based on filters, supporting sorting, pagination.
11541156
@@ -1166,7 +1168,10 @@ async def get_multi(
11661168
**kwargs: Filters to apply to the query, including advanced comparison operators for more detailed querying.
11671169
11681170
Returns:
1169-
A dictionary containing `"data"` with fetched records and `"total_count"` indicating the total number of records matching the filters.
1171+
A dictionary containing the data list and optionally the total count:
1172+
- With return_as_model=True: Dict with "data": List[SelectSchemaType]
1173+
- With return_as_model=False: Dict with "data": List[Dict[str, Any]]
1174+
- If return_total_count=True, includes "total_count": int
11701175
11711176
Raises:
11721177
ValueError: If `limit` or `offset` is negative, or if `schema_to_select` is required but not provided or invalid.

fastcrud/types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypeVar, Any
1+
from typing import TypeVar, Any, Dict, Union, List
22

33
from pydantic import BaseModel
44

@@ -9,3 +9,6 @@
99
UpdateSchemaType = TypeVar("UpdateSchemaType", bound=BaseModel)
1010
UpdateSchemaInternalType = TypeVar("UpdateSchemaInternalType", bound=BaseModel)
1111
DeleteSchemaType = TypeVar("DeleteSchemaType", bound=BaseModel)
12+
13+
GetMultiResponseDict = Dict[str, Union[List[Dict[str, Any]], int]]
14+
GetMultiResponseModel = Dict[str, Union[List[SelectSchemaType], int]]

0 commit comments

Comments
 (0)