title: SQLAlchemy: KeyError when looping through model objects in order to copy them
body: <p>I want to query rows and copy them while changing an attribute of each. Here's my code.</p>
  
  <pre><code> colObjs= db.session.query(Column).filter_by(chart_id=oldChartID).all()
   for colObj in colObjs:
     make_transient(colObj)
     print colObj.id
     del colObj.id
     colObj.chart_id= newChartID
     db.session.add(colObj)
     db.session.commit()
  </code></pre>
  
  <p>In this example, <code>colObjs</code> has two objects. I loop thru <code>colObjs</code>, going over each <code>colObj</code>. The first item in the loop copies fine. But when I try copying the second one, I get this error.</p>
  
  <pre><code>Traceback (most recent call last):
    File "/path/to/local/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
      return self.wsgi_app(environ, start_response)
    File "/path/to/local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
      response = self.handle_exception(e)
    File "/path/to/local/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
      reraise(exc_type, exc_value, tb)
    File "/path/to/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
      response = self.full_dispatch_request()
    File "/path/to/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "/path/to/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "/path/to/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
      rv = self.dispatch_request()
    File "/path/to/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "/path/to/myApp.py", line 859, in copyGraphic
      del colObj.id
    File "/path/to/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 227, in __delete__
      self.impl.delete(instance_state(instance), instance_dict(instance))
    File "/path/to/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 679, in delete
      del dict_[self.key]
  KeyError: 'id'
  </code></pre>
  
  <p>Furthermore, the output of the <code>print</code> statement on the first item of the loop shows the <code>coloObj</code> id, but the second one outputs <code>None</code>. </p>
  
  <p>Why does this error happen? How do I fix it? </p>