The following code fails on the last assert statement (SQLAlchemy
0.4.1):

--->8---
from __future__ import with_statement

import sqlalchemy as sa, logging
from sqlalchemy.orm import mapper, sessionmaker

logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
logging.basicConfig()

class ModelObject(object):

    def __init__(self, title):
        self.title = title

metadata = sa.MetaData()

objectTable = sa.Table(
    'Objects', metadata,
    sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
    sa.Column('title', sa.String(255), nullable=False),
)

objectsMapper = mapper(ModelObject, objectTable)

engine = sa.create_engine('sqlite://')
metadata.create_all(engine, checkfirst=True)

session = sessionmaker(bind=engine, autoflush=False,
transactional=False)()

obj1 = ModelObject(u'title-1.1')
with session.begin():
    session.save(obj1)
    # No session.flush() here. Is it OK? At least we did something to
save it.
obj1ID = obj1.id

session.clear()

obj1 = session.get(objectsMapper, obj1ID)
assert obj1.title==u'title-1.1'

obj1.title = u'title-1.2' # It's not intended to be saved

obj2 = ModelObject(u'title-2')
with session.begin():
    session.save(obj2)
obj2ID = obj2.id

session.clear()

obj2 = session.get(objectsMapper, obj2ID)
assert obj2.title==u'title-2'

obj1 = session.get(objectsMapper, obj1ID)
assert not session.autoflush
assert obj1.title==u'title-1.1' # But we didn't save/flush it!
--->8---

All modified objects are saved for each transaction and I see no way
to control this. Am I right? There is a lot of cases when such
behavior in unacceptable. Is it intended or a bug?

--~--~---------~--~----~------------~-------~--~----~
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