Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when params field name is keyword #1112

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions fastapi_pagination/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,17 @@ async def _pagination_params(*args: Any, **kwargs: Any) -> AsyncIterator[TAbstra
if IS_PYDANTIC_V2:
with suppress(ValueError, TypeError):
if issubclass(params, BaseModel):
sign_params = {**sign.parameters}
for name, field in params.model_fields.items():
name = field.alias or name
sign_params[name] = sign_params[name].replace(default=field)

sign = sign.replace(parameters=[*sign_params.values()])
sign_params = [
inspect.Parameter(
name=name,
kind=inspect.Parameter.KEYWORD_ONLY,
annotation=field.annotation,
default=field,
)
for name, field in params.model_fields.items()
]

sign = sign.replace(parameters=sign_params)

_pagination_params.__signature__ = sign # type: ignore[attr-defined]

Expand Down
Loading