title: How to rollback exceptions within celery when using sqlalchemy + postgresql
body: <p>This is what my code looks like</p>
  
  <pre><code>import transaction
  
  @app.task(name='task_name')
  def task_name_fn(*args, **kwargs):
     with transaction.manager:
         try:
            actual_fn(*args, **kwargs)
            transaction.commit()
         except:
            transaction.abort()
  </code></pre>
  
  <p>However, my <code>transaction.abort()</code> does not seem to be rolling back. All subsequent celery tasks on this worker fail. I get the following error </p>
  
  <blockquote>
    <p>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().</p>
  </blockquote>
  
  <p>What am I doing wrong?<br>
  Better question still, how would you write the <code>task_name_fn</code> so that this issue does not occur?</p>