whythawk / full-stack-fastapi-postgresql

Full stack, modern web application generator. Using FastAPI, PostgreSQL as database, Nuxt3, Docker, automatic HTTPS and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Internal server error on user profile creation instead of Validation Error

chapayevdauren opened this issue · comments

I tried to call create_user_profile view but it failed with Internal Server Error on schema check

user_in = schemas.UserCreate(password=password, email=email, full_name=full_name)
Traceback (most recent call last):
   File "/app/.venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
     result = await app(  # type: ignore[func-returns-value]
   File "/app/.venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
     return await self.app(scope, receive, send)
   File "/app/.venv/lib/python3.10/site-packages/fastapi/applications.py", line 270, in __call__
     await super().__call__(scope, receive, send)
   File "/app/.venv/lib/python3.10/site-packages/starlette/applications.py", line 124, in __call__
     await self.middleware_stack(scope, receive, send)
   File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
     raise exc
   File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
     await self.app(scope, receive, _send)
   File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/cors.py", line 92, in __call__
     await self.simple_response(scope, receive, send, request_headers=headers)
   File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/cors.py", line 147, in simple_response
     await self.app(scope, receive, send)
   File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
     raise exc
   File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
     await self.app(scope, receive, sender)
   File "/app/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
     raise e
   File "/app/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
     await self.app(scope, receive, send)
   File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 706, in __call__
     await route.handle(scope, receive, send)
   File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
     await self.app(scope, receive, send)
   File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
     response = await func(request)
   File "/app/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 235, in app
     raw_response = await run_endpoint_function(
   File "/app/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
     return await run_in_threadpool(dependant.call, **values)
   File "/app/.venv/lib/python3.10/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool
     return await anyio.to_thread.run_sync(func, *args)
   File "/app/.venv/lib/python3.10/site-packages/anyio/to_thread.py", line 33, in run_sync
     return await get_asynclib().run_sync_in_worker_thread(
   File "/app/.venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
     return await future
   File "/app/.venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 807, in run
     result = context.run(func, *args)
   File "/app/app/api/api_v1/endpoints/users.py", line 37, in create_user_profile
     user_in = schemas.UserCreate(password=password, email=email, full_name=full_name)
   File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
 pydantic.error_wrappers.ValidationError: 1 validation error for UserCreate
 password
   ensure this value has at least 8 characters (type=value_error.any_str.min_length; limit_value=8)

The trace tells you the validation error:

 password
   ensure this value has at least 8 characters (type=value_error.any_str.min_length; limit_value=8)

If you review the auth guide it lists the 'rules' which are validated against, including a minimum password length of 8 characters. Obviously, you can change this, but remember the implications in production.