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: Annotated's second args not work #10356

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Dragon-GCS
Copy link

Annotated not work when it annotate a pydantic annotated_types

@Kludex
Copy link
Member

Kludex commented Oct 1, 2023

What's the problem this solves?

Edit: I see... #10322.

@Dragon-GCS
Copy link
Author

Yes, when using Annoated[type_, ...] as a type annotation, if the second parameter is not FieldInfo or params.Depends, but instead is a param.Path or other param.XXX, it will result in the second parameter being ignored as a metadata attribute.

The following code(fastapi.dependencies.utils:333) snippet causes the type annotation to be ignored.

fastapi_annotations = [
    arg
    for arg in annotated_args[1:]
    if isinstance(arg, (FieldInfo, params.Depends))
]

And here(fastapi.dependencies.utils:398) create a new param.Path with type_annotation that is the first argument of annotion.

if is_path_param:
    field_info = params.Path(annotation=type_annotation)

So I fix it by replacing type_annotation with annotion to construct new param when it's second argument is not FieldInfo or params.Depends

@tiangolo tiangolo added feature New feature or request investigate labels Oct 2, 2023
@alejsdev alejsdev added p3 and removed investigate labels Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request p3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants