muenzerik / tournament-mgr

An open source tournament management system
0 stars 0 forks source link

Submits end sporadically up in "Server error" #7

Open muenzerik opened 3 years ago

muenzerik commented 3 years ago

User submits end up in Error 500 responses. When keeping resubmitting at some point, the submission is successful and all proceeds without issues and response and page renders well again.

This happens (at least) for submits in the admin menu, discipline score entry and also scoreboards request.

On server side, we can see the following logs:

2021-09-25T11:49:29.792934+00:00 app[web.1]: [2021-09-25 11:49:29,792] ERROR in app: Exception on /disciplines/Tischtennis [POST] 2021-09-25T11:49:29.792946+00:00 app[web.1]: Traceback (most recent call last): 2021-09-25T11:49:29.792947+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app 2021-09-25T11:49:29.792947+00:00 app[web.1]: response = self.full_dispatch_request() 2021-09-25T11:49:29.792962+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request 2021-09-25T11:49:29.792962+00:00 app[web.1]: rv = self.handle_user_exception(e) 2021-09-25T11:49:29.792963+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception 2021-09-25T11:49:29.792963+00:00 app[web.1]: reraise(exc_type, exc_value, tb) 2021-09-25T11:49:29.792963+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise 2021-09-25T11:49:29.792964+00:00 app[web.1]: raise value 2021-09-25T11:49:29.792964+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request 2021-09-25T11:49:29.792965+00:00 app[web.1]: rv = self.dispatch_request() 2021-09-25T11:49:29.792965+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request 2021-09-25T11:49:29.792965+00:00 app[web.1]: return self.view_functionsrule.endpoint 2021-09-25T11:49:29.792966+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask_login/utils.py", line 272, in decorated_view 2021-09-25T11:49:29.792966+00:00 app[web.1]: return func(*args, **kwargs) 2021-09-25T11:49:29.792967+00:00 app[web.1]: File "/app/app/routes.py", line 67, in discipline 2021-09-25T11:49:29.792967+00:00 app[web.1]: tournament = session.query(Tournaments).order_by(desc(Tournaments.Season)).first() 2021-09-25T11:49:29.792967+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3429, in first 2021-09-25T11:49:29.792968+00:00 app[web.1]: ret = list(self[0:1]) 2021-09-25T11:49:29.792968+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3203, in getitem 2021-09-25T11:49:29.792968+00:00 app[web.1]: return list(res) 2021-09-25T11:49:29.792969+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3534, in iter 2021-09-25T11:49:29.792969+00:00 app[web.1]: self.session._autoflush() 2021-09-25T11:49:29.792969+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1622, in _autoflush 2021-09-25T11:49:29.792969+00:00 app[web.1]: self.flush() 2021-09-25T11:49:29.792970+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2540, in flush 2021-09-25T11:49:29.792970+00:00 app[web.1]: self._flush(objects) 2021-09-25T11:49:29.792970+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2637, in _flush 2021-09-25T11:49:29.792970+00:00 app[web.1]: subtransactions=True 2021-09-25T11:49:29.792971+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 957, in begin 2021-09-25T11:49:29.792971+00:00 app[web.1]: self.transaction = self.transaction._begin(nested=nested) 2021-09-25T11:49:29.792971+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 317, in _begin 2021-09-25T11:49:29.792972+00:00 app[web.1]: self._assert_active() 2021-09-25T11:49:29.792972+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 296, in _assert_active 2021-09-25T11:49:29.792972+00:00 app[web.1]: code="7s2a", 2021-09-25T11:49:29.792973+00:00 app[web.1]: sqlalchemy.exc.InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "contraint_tournament_unique" 2021-09-25T11:49:29.792974+00:00 app[web.1]: DETAIL: Key ("ID_tournament", "ID_discipline")=(194c9f7c-1ba2-11ec-a431-06c99b7d7b05, 18491326-1deb-11ec-8cd6-02f8dc23bf5b) already exists.

muenzerik commented 3 years ago

Can be probably fixed with this: https://stackoverflow.com/questions/8870217/why-do-i-get-sqlalchemy-nested-rollback-error