Hi,

I'm trying to get my head around the attached scenario - unfortunately the 
documentation and aunt Google weren't too helpful :/

My expectation (up until now) was that an object that I mark as deleted 
would become useless for the application, similar to being detached after 
closing a session. If you run the attached code with SQLAlchemy (0.7 or 
0.8) then the object stays alive, stays attached and the application can't 
see that it has been deleted.

Is this intentional? Am I holding it wrong?

Thanks,
Christian

-- 
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 http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


from sqlalchemy import Column, Integer
from sqlalchemy.orm import object_session 
from sqlalchemy.orm.util import has_identity 
import sqlalchemy
import sqlalchemy.ext.declarative
import sqlalchemy.orm

engine = sqlalchemy.create_engine('sqlite:///:memory:')
session_factory = sqlalchemy.orm.scoped_session(
            sqlalchemy.orm.sessionmaker(bind=engine))

Object = sqlalchemy.ext.declarative.declarative_base()

class O(Object):

    __tablename__ = 'object'
    id = Column(Integer, primary_key=True)


def show_object_state(obj):
    if object_session(obj) is None and not has_identity(obj):
        return 'transient'
    if object_session(obj) is not None and not has_identity(obj):
        return 'pending'
    if object_session(obj) is None and has_identity(obj):
        return 'detached'
    if object_session(obj) is not None and has_identity(obj):
        return 'persistent'
    raise RuntimeError('unknown state')

Object.metadata.create_all(engine)
session = session_factory()

o = O()
o.id = 1

session.add(o)
session.commit()
session.delete(o)
session.commit()
session.close()

print session is object_session(o)
print show_object_state(o)
print o.id

Reply via email to