SQLAlchemy autocommiting?

Posted by muckabout on Stack Overflow See other posts from Stack Overflow or by muckabout
Published on 2010-03-12T12:06:28Z Indexed on 2010/03/12 12:47 UTC
Read the original article Hit count: 215

Filed under:
|
|

I have an issue with SQLAlchemy apparently committing. A rough sketch of my code:

trans = self.conn.begin()
try:            
    assert not self.conn.execute(my_obj.__table__.select(my_obj.id == id)).first()
    self.conn.execute(my_obj.__table__.insert().values(id=id))
    assert not self.conn.execute(my_obj.__table__.select(my_obj.id == id)).first()
except:
    trans.rollback()
    raise

I don't commit, and the second assert always fails! In other words, it seems the data is getting inserted into the database even though the code is within a transaction! Is this assessment accurate?

© Stack Overflow or respective owner

Related posts about sqlalchemy

Related posts about python