Closed
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
import sqlalchemy as sa
import sqlalchemy.exc as saexc
import sqlalchemy.ext.declarative as sadec
import sqlalchemy.sql as sasql
import sqlalchemy.orm as saorm
@sa.event.listens_for(saorm.Session, 'before_flush')
def handler1(session, flush_context, instances):
print 'handler1'
engine = sa.create_engine('sqlite://')
meta = sa.MetaData()
Base = sadec.declarative_base(metadata=meta)
class MySession(saorm.Session):
pass
# works
#sess = saorm.Session(bind=engine, autoflush=False)
# fails
#sessmaker = saorm.sessionmaker(bind = engine, autoflush = False)
#sess = sessmaker()
# fails
sess = MySession(bind=engine, autoflush=False)
class Anything(Base):
__tablename__ = 'families'
id = sa.Column(sa.Integer, primary_key=True)
meta.create_all(bind=engine)
@sa.event.listens_for(saorm.Session, 'before_flush')
def handler2(session, flush_context, instances):
print 'handler2'
f = Anything()
sess.add(f)
sess.commit()
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Mar 7, 2012
Michael Bayer (@zzzeek) wrote:
this is basically an issue with class generation in the event system.
sqlalchemy-bot commentedon Mar 7, 2012
Michael Bayer (@zzzeek) wrote:
this is not the fix but illustrates the issue, that new subclasses made after the fact don't get populated in the parent._clslevel mapping.
sqlalchemy-bot commentedon Mar 7, 2012
Michael Bayer (@zzzeek) wrote:
here's a patch that fixes, though we're having a heisenbug in test.sql.test_metadata:CatchAllEventsTest with it. Running test_metadata by itself passes, running all of -w sql, the patch fails, so something with the "event cleanup" code might be getting in the way here.
sqlalchemy-bot commentedon Mar 7, 2012
Michael Bayer (@zzzeek) wrote:
yeah it's the "clear" - which needs to hold onto those lists that are already created. if we just make that check for parent._cls more liberal then it's OK:
this incurs a lot of unnecessary, instance-level calls to
update_subclass()
though, in the usual case that there's no events set up, so let's keep tryingsqlalchemy-bot commentedon Mar 7, 2012
Michael Bayer (@zzzeek) wrote:
this one should do it:
sqlalchemy-bot commentedon Mar 8, 2012
Michael Bayer (@zzzeek) wrote:
8696a45
sqlalchemy-bot commentedon Mar 8, 2012
Changes by Michael Bayer (@zzzeek):