Re: [sqlalchemy] ObjectDeletedError when query.delete() hits an expired item

2011-04-07 Thread Michael Bayer
it is a bug and ticket 2122 has the fix for this.  However I'd like to target 
this at 0.7 since it rearranges things in update()/delete() significantly and 
I'd like to add test coverage for all the changes that have been made. The 
workaround for 0.6 is to pass False or "fetch" to the delete() method so that 
the in-session evaluation isn't called on expired objects.


On Apr 7, 2011, at 10:33 AM, Bobby Impollonia wrote:

> Hi. With SQLA 0.6.6, the program below fails on the last line with
> ObjectDeletedError. Is this expected or a bug?
> 
> from sqlalchemy import create_engine, MetaData, Column, Unicode
> from sqlalchemy.orm import sessionmaker
> from sqlalchemy.ext.declarative import declarative_base
> 
> engine = create_engine('sqlite:///:memory:')
> metadata = MetaData(bind = engine)
> session = sessionmaker(bind = engine)()
> Base = declarative_base(metadata = metadata)
> 
> class Entity(Base):
>__tablename__ = 'entity'
>name = Column(Unicode(128), primary_key = True)
> 
> metadata.create_all()
> e = Entity(name = u'hello')
> session.add(e)
> session.flush()
> session.expire(e)
> session.query(Entity).filter_by(name = u'hello').delete()
> 
> -- 
> 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 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] ObjectDeletedError when query.delete() hits an expired item

2011-04-07 Thread Bobby Impollonia
Hi. With SQLA 0.6.6, the program below fails on the last line with
ObjectDeletedError. Is this expected or a bug?

from sqlalchemy import create_engine, MetaData, Column, Unicode
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite:///:memory:')
metadata = MetaData(bind = engine)
session = sessionmaker(bind = engine)()
Base = declarative_base(metadata = metadata)

class Entity(Base):
__tablename__ = 'entity'
name = Column(Unicode(128), primary_key = True)

metadata.create_all()
e = Entity(name = u'hello')
session.add(e)
session.flush()
session.expire(e)
session.query(Entity).filter_by(name = u'hello').delete()

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.