this is a bug, ticket #1150 has been added.  delete() should be adding  
the object to the session which is not the case if you attempt to  
"assert user in session".


On Aug 22, 2008, at 3:37 AM, Marco De Felice wrote:

>
> While migrating I came across the following sequence of actions, I had
> some old code that called session.close() elsewhere in the application
> and also I tend to use sqlalchemy as a temporary object cache knowing
> this is somewhat discouraged.
> Anyway is it correct that nothing happens when calling that
> session.delete(user) ??
>
> import sqlalchemy as sqa
> import sqlalchemy.orm as sqorm
>
> class User(object): pass
>
> dsn = """sqlite:///"""
> engine = sqa.create_engine(dsn)
> engine.echo = True
>
> md = sqa.MetaData()
> md.bind = engine
>
> users = sqa.Table('users', md,
>    sqa.Column('id', sqa.Integer, primary_key=True),
>    sqa.Column('name', sqa.String),
>    sqa.Column('email', sqa.String))
>
> users.mapper = sqorm.mapper(User, users)
>
> Session = sqorm.sessionmaker(bind=engine, autocommit=True)
>
> if __name__ == "__main__":
>
>    session = Session()
>    users.create()
>
>    session.begin()
>
>    user = User()
>    user.name='test'
>    user.email='[EMAIL PROTECTED]'
>
>    session.add(user)
>
>    session.flush()
>    session.commit()
>
>    #accidentally call close.
>    session.close()
>
>    #try to delete the cached user, nothing appens
>    session.begin()
>    session.delete(user)
>    session.flush()
>    session.commit()
>
>    #the user is still there
>    users = session.query(User).all()
>    for user in users:
>        print user.name, user.email
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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