ClimateMind / climatemind-backend

Your climate action is here 🌎 Our API is a source for learning how climate change personally affects you and the things you care about most. Additionally, it will teach a scientifically proven method for communicating to others that climate change is a personally relevant issue to inspire action.
https://contribute.climatemind.org/v/rest-api/
MIT License
18 stars 19 forks source link

Fix "List index out of range" for sorted_aligned_effects #506

Open Svenstar74 opened 8 months ago

Svenstar74 commented 8 months ago

Describe the bug

The problem occurs when I complete the quiz as a userB. It doesn't happen always but very often for me. The backend responds with a 500 error, which also breaks the frontend, because there are no alignment scores, etc. to display.

When I have the backend running locally, I get the error message, that the list index is out of range for sorted_aligned_effects[2] in line 44 below. If I print the sorted_aligned_effects list, I indeed can see that there are only two entries.

To Reproduce

Here's a video that shows me reproducing it. Please note, that it also happens for other combinations of answers. Selecting always the first answer is just more reliable for me to get the error.

https://github.com/ClimateMind/climatemind-backend/assets/78958483/03c1469b-3ead-4c84-aca0-77092332b894

Expected behavior

I would assume that the fix would involve to guarantee that the list always has three items, so that the api call doesn't fail.

Task