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

header Parameter throws pydantic error in 0.7.1 #66

Closed
philvarner opened this issue Jan 27, 2022 · 4 comments
Closed

header Parameter throws pydantic error in 0.7.1 #66

philvarner opened this issue Jan 27, 2022 · 4 comments

Comments

@philvarner
Copy link

These docs:
https://starlite-api.github.io/starlite/usage/3-parameters/#header-and-cookie-parameters

have the example for using a header parameter as:

@get(path="/users/{user_id:uuid}/")
async def get_user(
    user_id: UUID4,
    token: Parameter(header="X-API-KEY"),
) -> User:
    ...

when I try the (slightly modified) resource (since I don't have User in my app):

@get(path="/users/{user_id:uuid}/")
async def get_user(
    user_id: UUID4,
    token: Parameter(header="X-API-KEY"),
) -> Request:
    ...

I get the error

RuntimeError: error checking inheritance of FieldInfo(default=PydanticUndefined, alias='', extra={'header': 'X-API-KEY', 'cookie': None, 'query': None, 'required': True, 'examples': None, 'external_docs': None, 'content_encoding': None}) (type: FieldInfo)

This is on python v3.9.7 and pydantic 1.9.0 (which I'm not installing explicitly, and I think got installed as a dependency of starlite)

@Goldziher
Copy link
Contributor

Peculiar. I'll check this out.

@Goldziher
Copy link
Contributor

Hmm, this is another error in the documentation

This is how it should be:

@get(path="/users/{user_id:uuid}/")
async def get_user(
    user_id: UUID4,
    token: str = Parameter(header="X-API-KEY"),
) -> User:
    ...

Notice the typing difference in token - Parameter is a default function value, not a type. I will update the docs with fixes.

@Goldziher
Copy link
Contributor

well, apparently there is also a bug involved - but unrelated to this issue. I am publishing 0.7.2 momentarily, which will also update the docs. Please check that this issue is resolved for you - and if so, close this issue.

@philvarner
Copy link
Author

This works in 0.7.2 -- thanks!

@philvarner philvarner changed the title header Parameter throws pydantic error header Parameter throws pydantic error in 0.7.1 Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants