Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This session is in 'prepared' state; no further SQL can be emitted within this transaction. #13

Open
Foorack opened this issue Mar 20, 2021 · 0 comments

Comments

@Foorack
Copy link
Member

Foorack commented Mar 20, 2021

If a scheduled cron task is running at the exact same time a salto request comes in then the Database throws an error due to multi-thread access. Create one Session per thread instead, see: https://stackoverflow.com/questions/39126810/this-session-is-in-prepared-state-no-further-error-with-sqlalchemy-using-sc

2021-03-20 15:00:02,704 ERROR Exception on /salto/mek [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.9/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/srv/koseki/koseki/plugins/salto/salto.py", line 58, in salto_mek
    self.storage.session.query(Person).filter_by(state="active").all()
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/query.py", line 3373, in all
    return list(self)
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/query.py", line 3535, in __iter__
    return self._execute_and_instances(context)
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/query.py", line 3556, in _execute_and_instances
    conn = self._get_bind_args(
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/query.py", line 3571, in _get_bind_args
    return fn(
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/query.py", line 3550, in _connection_from_session
    conn = self.session.connection(**kw)
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/session.py", line 1142, in connection
    return self._connection_for_bind(
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/session.py", line 1150, in _connection_for_bind
    return self.transaction._connection_for_bind(
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/session.py", line 409, in _connection_for_bind
    self._assert_active()
  File "/usr/local/lib/python3.9/dist-packages/sqlalchemy/orm/session.py", line 282, in _assert_active
    raise sa_exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: This session is in 'prepared' state; no further SQL can be emitted within this transaction.
2021-03-20 15:00:05,877 INFO Job "MetricPlugin.calc_metric (trigger: cron[minute='0', second='0'], next run at: 2021-03-20 16:00:00 CET)" executed successfully```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant