[Python] Why FastAPI cannot parse UUID by pattern while Regex101 can?

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    I have some FastAPI application:

    from typing import Annotated

    import uvicorn
    from fastapi import FastAPI, Query
    from pydantic import constr

    app = FastAPI()


    @app.get("search")
    async def search(
    partner_ids: Annotated[
    constr(pattern="((^|[,])[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})+"),
    Query(),
    ] = "ca930bc7-f4cf-4b10-9c6f-7db13b6ab4f0",
    ):
    pass


    if __name__ == "__main__":
    uvicorn.run("uuid_list:app", reload=True, port=8004)


    The problem with it is validation of partner_ids does not work:

    [​IMG]

    At the same time regex101 finds uuid:

    [​IMG]

    What's wrong with FastAPI?

    Upd. The regex is for comma separated list of uuids.

    Continue reading...

Compartilhe esta Página