title: Flask + SQLAlchemy [ Determine Success of Commit ]
body: <p>I have a view in flask that I want to use to display success when an object from a POST request is successfully committed.</p>
  
  <p>In the controller, I have</p>
  
  <pre><code>us = User(data_that_is_not_valid)
  db_session.add(us)
  db_session.commit()
  </code></pre>
  
  <p>As of now, db_commit() throws an exception when the object can't be committed. Is there a more friendly way that just returns true or false to specify whether the object has been added to the database without throwing an error? </p>
  
  <p>EDIT: Added copy of exception</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.8.0-py2.7-linux-x86_64.egg/sqlalchemy/orm/scoping.py", line 149, in do
      return getattr(self.registry(), name)(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.8.0-py2.7-linux-x86_64.egg/sqlalchemy/orm/session.py", line 719, in commit
      self.transaction.commit()
    File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.8.0-py2.7-linux-x86_64.egg/sqlalchemy/orm/session.py", line 350, in commit
      self._assert_active(prepared_ok=True)
    File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.8.0-py2.7-linux-x86_64.egg/sqlalchemy/orm/session.py", line 192, in _assert_active
      % self._rollback_exception
  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: (IntegrityError) column email is not unique u'INSERT INTO users (name, email, password) VALUES (?, ?, ?)' ('test', 'test@test.com', 'test')
  </code></pre>