Skip to content

Conversation

dmontagu
Copy link
Contributor

Closes #6623

This is necessary for FastAPI to to produce a collection of query param dependencies from a pydantic dataclass:

from typing import Union

from fastapi import FastAPI, Depends

import pydantic
from pydantic.dataclasses import dataclass as pydantic_dataclass

app = FastAPI()


@pydantic_dataclass()
class QueryParams:
    q: Union[str, None] = None
    skip: int = pydantic.Field(default=0)
    limit: int = 100


@app.get("/")
def home(query_params: QueryParams = Depends()):
    return query_params

Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works as expected with FastAPI 👍

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 12, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: cce73c4
Status: ✅  Deploy successful!
Preview URL: https://275dc5d4.pydantic-docs2.pages.dev
Branch Preview URL: https://dataclass-signature.pydantic-docs2.pages.dev

View logs

@dmontagu dmontagu enabled auto-merge (squash) July 12, 2023 20:22
@Kludex Kludex disabled auto-merge July 12, 2023 20:33
@dmontagu dmontagu enabled auto-merge (squash) July 12, 2023 20:40
@dmontagu dmontagu merged commit c2e02fc into main Jul 12, 2023
@dmontagu dmontagu deleted the dataclass-signature branch July 12, 2023 20:47
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

Successfully merging this pull request may close these issues.

[PYD-179] Pydantic dataclasses have under-specified signature
2 participants