python - SQLAlchemy query occassionally throws StatementError -
i have flask application uses sqlalchemy connected mysql db running on production server (ubuntu machine).
75% of times issue post request application raises statementerror following stacktrace.
[2015-06-18 17:25:46,512] {/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/flask/app.py:1423} error - exception on /conjugate/conjugate [post] traceback (most recent call last): file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) file "./conjugate.py", line 169, in conjugate translation in get_translations(lang, verb)], file "./conjugate.py", line 80, in get_translations entry in session.query(translation).filter_by(lang=lang, english=english): file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2515, in __iter__ return self._execute_and_instances(context) file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2530, in _execute_and_instances result = conn.execute(querycontext.statement, self._params) file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 914, in execute return meth(self, multiparams, params) file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement compiled_sql, distilled_params file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1078, in _execute_context none, none) file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1339, in _handle_dbapi_exception exc_info file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause reraise(type(exception), exception, tb=exc_tb) file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1071, in _execute_context conn = self._revalidate_connection() file "/home/dsaltares/conjugate/env/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 391, in _revalidate_connection "can't reconnect until invalid " statementerror: (sqlalchemy.exc.invalidrequesterror) can't reconnect until invalid transaction rolled [sql: u'select translations.lang translations_lang, translat ions.verb translations_verb, translations.english translations_english, translations.description translations_description \nfrom translations \nwhere translations.l ang = %s , translations.english = %s'] [parameters: [immutabledict({})]]
the remaining 25% query works fine , returns expected data. these queries spaced in time, it's not trashing service.
the query crashing @ is
try: entry in session.query(translation).filter_by(lang=lang, english=english): translations.append({ 'lang': lang, 'english': english, 'verb': entry.verb, 'description': entry.description }) except: app.logger.error('error querying translations (%s, %s)\n%s' % (lang, english, traceback.format_exc())) raise
the translation mapper:
from sqlalchemy.ext.declarative import declarative_base sqlalchemy import column, integer, string base = declarative_base() class translation(base): __tablename__ = 'translations' lang = column(string(10), primary_key=true) verb = column(string(25), primary_key=true) english = column(string(25), primary_key=true) description = column(string) def __repr__(self): return "<translation(lang='%s', verb='%s', english='%s'>" % (self.lang, self.verb, self.english)
any ideas may be? need provide more information?
Comments
Post a Comment