I spent 4 hours to replicate the error correctly while minimizing the
code. I can't find a way to attach a file so I will paste the code
here:
import sqlalchemy as sa
from sqlalchemy import create_engine, MetaData, orm
from sqlalchemy import Column, ForeignKey
from sqlalchemy import Integer, String
from sqlalchemy.orm import mapper
class Object(object):
pass
class Q(Object):
pass
class A(Object):
pass
class C(Object):
pass
class WC(C):
pass
engine = create_engine('sqlite:///:memory:', echo=True)
sm = orm.sessionmaker(autoflush=True, transactional=True, bind=engine)
SA_Session = orm.scoped_session(sm)
SA_Metadata = MetaData()
object_table = sa.Table('Object',
SA_Metadata,
Column('ObjectID', Integer,
primary_key=True),
Column('Type', String(1), nullable=False))
q_table = sa.Table('Q',
SA_Metadata,
Column('QID', Integer,
ForeignKey('Object.ObjectID'),primary_key=True))
c_table = sa.Table('C',
SA_Metadata,
Column('CID', Integer,
ForeignKey('Object.ObjectID'),primary_key=True))
wc_table = sa.Table('WC',
SA_Metadata,
Column('WCID', Integer, ForeignKey('C.CID'),
primary_key=True))
a_table = sa.Table('A',
SA_Metadata,
Column('AID', Integer,
ForeignKey('Object.ObjectID'),primary_key=True),
Column('QID', Integer, ForeignKey('Q.QID')),
Column('CID', Integer, ForeignKey('C.CID')))
mapper(Object, object_table, polymorphic_on=object_table.c.Type,
polymorphic_identity='O')
mapper(Q, q_table, inherits=Object, polymorphic_identity='Q')
mapper(C, c_table, inherits=Object, polymorphic_identity='C')
mapper(WC, wc_table, inherits=C, polymorphic_identity='W')
mapper(A, a_table, inherits=Object, polymorphic_identity='A',
properties = {
'Q' : orm.relation(Q,
primaryjoin=a_table.c.QID==q_table.c.QID,
backref='As'),
'C' : orm.relation(C,
primaryjoin=a_table.c.CID==c_table.c.CID,
backref='A',
uselist=False)
}
)
SA_Metadata.create_all(engine)
def generate_error():
q = Q()
for j in range(307): #at 306 the error does not pop out (depending
on recursion depth)
a = A()
a.Q = q
a.C = WC()
SA_Session.save(q)
SA_Session.commit() #here the error pops out
def dont_generate_error():
q = Q()
SA_Session.save(q)
for j in range(600):
a = A()
a.Q = q
a.C = WC()
SA_Session.commit()
dont_generate_error()
generate_error()
I hope I'll hear from you if you replicate the error.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---