I want to query rows and copy them while changing an attribute of each. Here's my 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() In this example, `colObjs` has two objects. I loop thru `colObjs`, going over each `colObj`. The first item in the loop copies fine. But when I try copying the second one, I get this error. 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' Furthermore, the output of the `print` statement on the first item of the loop shows the `coloObj` id, but the second one outputs `None`. Why does this error happen? How do I fix it? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.