Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonypelletier committed Oct 6, 2023
1 parent 6fbf927 commit 058a317
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fastapi_crudrouter/core/_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional, Type, Any

from fastapi import Depends, HTTPException
from pydantic import create_model
from pydantic import create_model, __version__ as pydantic_version

from ._types import T, PAGINATION, PYDANTIC_SCHEMA

Expand All @@ -14,6 +14,7 @@ def __init__(self, *args, **kwargs) -> None: # type: ignore

def get_pk_type(schema: Type[PYDANTIC_SCHEMA], pk_field: str) -> Any:
try:
# for handle pydantic 2.x migration
if int(pydantic_version.split(".")[0]) >= 2:
return schema.model_fields[pk_field].annotation
else:
Expand All @@ -30,8 +31,6 @@ def schema_factory(
"""

# for handle pydantic 2.x migration
from pydantic import __version__ as pydantic_version

if int(pydantic_version.split(".")[0]) >= 2:
# pydantic 2.x
fields = {
Expand Down Expand Up @@ -90,3 +89,4 @@ def pagination(skip: int = 0, limit: Optional[int] = max_limit) -> PAGINATION:
return {"skip": skip, "limit": limit}

return Depends(pagination)

0 comments on commit 058a317

Please sign in to comment.