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

[BUG] cbv and path params create strange behaviour #264

Open
kickIDnoah opened this issue Nov 9, 2022 · 1 comment
Open

[BUG] cbv and path params create strange behaviour #264

kickIDnoah opened this issue Nov 9, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@kickIDnoah
Copy link

While using the @cbv i encountered the problem that i couldn't use the endpoint without path params on a similar path.
It somehow messes with the validator, i think?

from fastapi import APIRouter, FastAPI
from fastapi_utils.cbv import cbv
from pydantic.types import UUID4
from starlette.testclient import TestClient

router = APIRouter()


@cbv(router)
class CBV:

    @router.post("/test")
    def test_post(self):
        return ''


    @router.get("/test/{uuid}")
    def test_post(self, uuid: UUID4):
        return uuid


app = FastAPI()
app.include_router(router)
client = TestClient(app)

print(client.post("/test").json())

output:

{
  "detail":[
    {
      "loc":[
        "query",
        "self"
      ],
      "msg":"field required",
      "type":"value_error.missing"
    }
  ]
}

Expected behavior
both endpoints should be just available

Environment:

fastapi_utils_version: 0.2.1
fastapi_version: 0.85.2
pydantic version: 1.10.2
pydantic compiled: True
install path: ...\fastapi_test\venv\Lib\site-packages\pydantic
python version: 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)]
platform: Windows-10-10.0.22621-SP0
optional deps. installed: ['dotenv', 'typing-extensions']
@kickIDnoah kickIDnoah added the bug Something isn't working label Nov 9, 2022
@hgalytoby
Copy link

hgalytoby commented Jun 9, 2023

Your function names cannot be repeated.

@cbv(router)
class CBV:

    @router.post("/test")
    def test_post(self):
        return ''


    @router.get("/test/{uuid}")
    def test_get(self, uuid: UUID4):
        return uuid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants