> On Dec 1, 2014, at 9:01 AM, Guido Winkelmann <[email protected]> > wrote: > > This is the full text of the exception that I'm getting: > > in _assert_active > % self._rollback_exception > 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: > (TransactionRollbackError) could not serialize access due to concurrent update > 'UPDATE jobs SET state=%(state)s, time_started=%(time_started)s WHERE jobs.id > = %(jobs_id)s' {'state': 105, 'time_started': datetime.datetime(2014, 11, 26, > 17, 8, 56, 651872), 'jobs_id': 2444L} > > You're right, there's something going wrong here.
this is a simple issue, you need to always call session.rollback() when an exception occurs. This error illustrates that a Session has already experienced the concurrency issue you’re trying to catch, yet the operation continues to proceed on that Session which is now in an invalid state. FAQ on this is at: http://docs.sqlalchemy.org/en/rel_0_9/faq.html#this-session-s-transaction-has-been-rolled-back-due-to-a-previous-exception-during-flush-or-similar > > We are using Celery to run some tasks asynchronously (the main application is > a WSGI web app) and Flask-SQLAlchemy to get a db session object. It turns out > that in combination, that means that db session objects from Flask-SQLAlchemy > get reused between tasks running on the same celery worker. That doesn’t sound right and you should organize things so that a Session is used pretty much for just one series of operations, then you get rid of it after that thing (in a transaction) is complete. More guidelines: http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#when-do-i-construct-a-session-when-do-i-commit-it-and-when-do-i-close-it -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
