fastsurvey / backend

FastSurvey's backend that's crunching the data
1 stars 0 forks source link

Server error when updating survey #65

Closed dostuffthatmatters closed 3 years ago

dostuffthatmatters commented 3 years ago

I am working on the survey dostuffthatmatters.disrespectful-chicken.

When trying to update the survey (changing the option fields required from true to false), the backend responds with a 500. The server logs say:

INFO:     127.0.0.1:56383 - "PUT /users/dostuffthatmatters/surveys/disrespectful-chicken HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 390, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/middleware/cors.py", line 86, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/middleware/cors.py", line 142, in simple_response
    await self.app(scope, receive, send)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
    response = await func(request)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/fastapi/routing.py", line 214, in app
    raw_response = await run_endpoint_function(
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/fastapi/routing.py", line 149, in run_endpoint_function
    return await dependant.call(**values)
  File "./app/cryptography/access.py", line 23, in wrapper
    return await func(**kwargs)
  File "./app/main.py", line 146, in update_survey
    await survey_manager.update(
  File "./app/survey.py", line 100, in update
    survey = await self.fetch(username, survey_name)
  File "./app/survey.py", line 50, in fetch
    return self.cache.fetch(username, survey_name)
  File "./app/survey.py", line 158, in fetch
    return self._cache[survey_id]
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/cachetools/lru.py", line 14, in __getitem__
    value = cache_getitem(self, key)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/cachetools/cache.py", line 41, in __getitem__
    return self.__missing__(key)
  File "/Users/dostuffthatmatters/Documents/projects/current/fastsurvey/backend/venv/lib/python3.8/site-packages/cachetools/cache.py", line 68, in __missing__
    raise KeyError(key)
KeyError: 'dostuffthatmatters.disrespectful-chicken'

Do you need any more info or can you reproduce it? I am running on commit hash 2e425a0.


The config, in case you need it:

{
    "title": "We need more surveys!",
    "description": "",
    "survey_name": "disrespectful-chicken",
    "start": 1630416680,
    "end": 1630503080,
    "draft": true,
    "fields": [
        {
            "title": "Data Privacy",
            "description": "I accept the terms and conditions",
            "type": "option",
            "required": false
        }
    ]
}
empicano commented 3 years ago

Can reproduce. Very weird error, because during testing the update works fine, but not when I run uvicorn myself ...

empicano commented 3 years ago

So, newest version should work (if you want to stay on 2e425a0 for now, the change is just a few lines)

Can you confirm that it works now?

I'm probably going to remove the caching in the next days again for now, the few milliseconds are not worth the headaches 😅

dostuffthatmatters commented 3 years ago

The fix works! And the deployed backend is really fast :)

I am using the newest deployed backend a4f154a. Also the new authentication works great. Didn't have to change a lot except for the types on my side.