title: sqlalchemy rollback in INSERTS
body: <p>I have a small question. I'm inserting a long array of data into a DB, but it can happen that some of the new rows throw an IntegrityError exception. That's fine and I can easily recognize them. The problem is, when I rollback to undo this "fake" insertion, all the previous rows are also deleted.</p>
  
  <p>What I want to do then, is to rollback to the immediate previous status and continue with the next Insert.</p>
  
  <pre><code>import sqlalchemy as alc
  
  def insert(self, specs):
      #do stuff to transfor specs in data_db
  
      entry = Check_Point(data_db)
      session.add(entry)
  
      try:
          session.flush()
  
      except alc.exc.IntegrityError:
          print 'int Error'
          session.rollback()
  </code></pre>
  
  <p>So, researching a little bit, I found this:</p>
  
  <p><a href="http://docs.sqlalchemy.org/en/rel_0_7/orm/session.html#using-savepoint" rel="nofollow">http://docs.sqlalchemy.org/en/rel_0_7/orm/session.html#using-savepoint</a></p>
  
  <pre><code>for record in records:
      try:
          with session.begin_nested():
              session.merge(record)
      except:
          print "Skipped record %s" % record
  session.commit()
  </code></pre>
  
  <p>But I cannot really get it to work, if "records" is an array of the objects to be inserted (in my case instances of Check_Point). I get the following error:</p>
  
  <blockquote>
    <p>This Session's transaction has been rolled back by a nested rollback() call.  To begin a new transaction, issue Session.rollback() first</p>
  </blockquote>
  
  <p>I'm close to solve the problem but need some help.</p>
  
  <p>Thanks in advance!</p>