jonra1993 / fastapi-alembic-sqlmodel-async

This is a project template which uses FastAPI, Pydantic 2.0, Alembic and async SQLModel as ORM. It shows a complete async CRUD using authentication and role base access control.
MIT License
964 stars 150 forks source link

Add user to group does not work #5

Closed Stefan2409 closed 2 years ago

Stefan2409 commented 2 years ago

How to reproduce the error:

  1. Start dev environment
  2. Make migrations
  3. Login as admin user via Swagger UI
  4. Create new user
  5. Create new group
  6. Add created user to created group

I'm getting the following error when I try to add a user to a group (The user and group ids are correct):

fastapi_server  | INFO:     172.20.0.6:52558 - "POST /api/v1/group/add_user/79c7fc32-99fc-4a0a-ac3e-6db8516fb8b2/f99a6f9c-4c16-42fc-b79e-e8e1e982346c HTTP/1.1" 500 Internal Server Error
fastapi_server  | ERROR:    Exception in ASGI application
fastapi_server  | Traceback (most recent call last):
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
fastapi_server  |     result = await app(self.scope, self.receive, self.send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
fastapi_server  |     return await self.app(scope, receive, send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/fastapi/applications.py", line 261, in __call__
fastapi_server  |     await super().__call__(scope, receive, send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
fastapi_server  |     await self.middleware_stack(scope, receive, send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 181, in __call__
fastapi_server  |     raise exc
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in __call__
fastapi_server  |     await self.app(scope, receive, _send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/middleware/cors.py", line 92, in __call__
fastapi_server  |     await self.simple_response(scope, receive, send, request_headers=headers)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/middleware/cors.py", line 147, in simple_response
fastapi_server  |     await self.app(scope, receive, send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
fastapi_server  |     raise exc
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 71, in __call__
fastapi_server  |     await self.app(scope, receive, sender)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
fastapi_server  |     raise e
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
fastapi_server  |     await self.app(scope, receive, send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 656, in __call__
fastapi_server  |     await route.handle(scope, receive, send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 259, in handle
fastapi_server  |     await self.app(scope, receive, send)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 61, in app
fastapi_server  |     response = await func(request)
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 227, in app
fastapi_server  |     raw_response = await run_endpoint_function(
fastapi_server  |   File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 160, in run_endpoint_function
fastapi_server  |     return await dependant.call(**values)
fastapi_server  |   File "/code/./app/api/api_v1/endpoints/group.py", line 70, in add_user_to_group
fastapi_server  |     group = await crud.group.add_user_to_group(db_session, user=user, group_id=group_id)
fastapi_server  |   File "/code/./app/crud/crud_group.py", line 16, in add_user_to_group
fastapi_server  |     group = await super().get(db_session, group_id)
fastapi_server  | TypeError: get() takes 2 positional arguments but 3 were given

I don't understand the TypeError because we only give 2 arguments not 3 like in the error message....

jonra1993 commented 2 years ago

Hello @Stefan2409 thanks for opening this bug I have solved it here https://github.com/jonra1993/fastapi-alembic-sqlmodel-async/commit/b2efd4d040de66210cb71630f2239c854e34e50c

Please make a pull of the latest main branch code to test it and it is not needed to run the new Alembic migration "step2" despite you previously changed the database model.