Hi everyone!
I'm sorry, I'm using SQLA 0.5rc1 with autocommit=True, and I'm having
a problem with rollbacks.. It looks to me that whenever I try to save
an object that triggers some kind of exception (thus triggering a
rollback) I lose that object's previous state..

To elaborate, here's a simple testcase:



from sqlalchemy import Column, String, Integer
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class DataTest(Base):
    """ Simple class with versioning """
    id = Column(Integer, primary_key = True)
    propstring = Column(String)
    version = Column(Integer)
    __tablename__ = "t"
    __mapper_args__ = { "version_id_col" : version }

def save(session, x):
    """ Save x with begin/commit """
    session.begin()
    session.add(x)
    session.commit()

en=create_engine("sqlite:///:memory:", echo=True)
Base.metadata.create_all(en)
maker = sessionmaker(en)
session = maker(autocommit=True)

# Save a DataTest...
x=DataTest()
x.propstring = "test"
save(session, x)

# ...then simulate a concurrent modification
x.version=0
try:
    save(session, x)
except:
    session.rollback()

# I'd expect x.version to be the way it was
assert x.version == 0



Am I misunderstanding something? Is there a way to keep "x" the way it
was before the save() ?
Many thanks for your attention!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to