tiangolo / fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production
https://fastapi.tiangolo.com/
MIT License
73.13k stars 6.16k forks source link

pydantic error: look-around, including look-ahead and look-behind, is not supported #11755

Closed a10201 closed 1 week ago

a10201 commented 1 week ago

Privileged issue

Issue Content

from fastapi import FastAPI, Request, Path

from pydantic import ConfigDict

from core import settings

app = FastAPI()

@app.get("/{url:path}", summary="前端网页", response_class=str)
async def frontend_page(
    request: Request,
    url: str = Path(
        ...,
        pattern=f"^(?!{settings.OPENAPI_V1_STR}/).*",
        # json_schema_extra=ConfigDict(regex_engine="python-re"),
    ),
):

    return "success"

# 主程序入口
if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host=settings.OPENAPI_HOST, port=7791)

Python、Pydantic 和 OS 版本

pydantic version: 2.7.3 pydantic-core version: 2.18.4 fastapi 0.111.0 pydantic-core build: profile=release pgo=true install path: /.venv/lib/python3.12/site-packages/pydantic python version: 3.10.12

code error details

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\src\project\yjerp\ims\test.py", line 11, in async def frontend_page( File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\fastapi\routing.py", line 944, in decorator self.add_api_route( File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\fastapi\routing.py", line 883, in add_api_route route = route_class( File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\fastapi\routing.py", line 513, in init self.dependant = get_dependant(path=self.path_format, call=self.endpoint) File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\fastapi\dependencies\utils.py", line 261, in get_dependant type_annotation, depends, param_field = analyze_param( File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\fastapi\dependencies\utils.py", line 444, in analyze_param field = create_response_field( File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\fastapi\utils.py", line 99, in create_response_field return ModelField(*kwargs) # type: ignore[arg-type] File "", line 6, in init File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\fastapi_compat.py", line 120, in post_init__ raise e File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\fastapi_compat.py", line 117, in post_init self._type_adapter: TypeAdapter[Any] = TypeAdapter(ConfigStr) File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\pydantic\type_adapter.py", line 222, in init__ validator = create_schema_validator( File "D:\down_app\Anaconda3\envs\ims\lib\site-packages\pydantic\plugin_schema_validator.py", line 49, in create_schema_validator return SchemaValidator(schema, config) pydantic_core._pydantic_core.SchemaError: Error building "str" validator: SchemaError: regex parse error: ^(?!/api/v1/). ^^^ error: look-around, including look-ahead and look-behind, is not supported