I have the following code:

from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session, relationship, backref


e = create_engine('sqlite:////tmp/test.db', echo=True)
Base = declarative_base()
Base.metadata = MetaData(e)


class Node(Base):
    __tablename__ = 'nodes'

    id = Column(Integer, primary_key=True)

class Item(Base):
    __tablename__ = 'items'

    id = Column(Integer, primary_key=True)
    node_id = Column(Integer, ForeignKey(Node.id))
    item_type = Column(String(24), default='item')

    node = relationship(Node, lazy=True, uselist=False,
        backref=backref('objects', lazy=True, uselist=True))

    __mapper_args__ = {
        'polymorphic_identity': 'item',
        'polymorphic_on': 'item_type',
        'with_polymorphic': '*',
        }

class PolyItem(Item):
    __tablename__ = 'poly_items'
    
    id = Column(Integer, ForeignKey(Item.id), primary_key=True)

    __mapper_args__ = {
        'polymorphic_identity': 'polyitem',
        }

    item = relationship(Item, lazy=True)

if __name__ == '__main__':
    Base.metadata.drop_all()
    Base.metadata.create_all()
    
    node = Node()
    item = PolyItem(node=node)
    session = Session(e)
    session.add(node)
    session.add(item)
    session.commit()
    
    node = session.query(Node).first()
    session.delete(node)
    session.commit()

This runs fine in 0.7.9 and 0.8.0. However, if I change PolyItem.item to 
relationship(Item, lazy=False), 0.7.9 continues to function, while 0.8.0 
and 0.8.1 go into infinite loops and eventually fail due to maximum 
recursion exceeded. The adding to the db works, it's the delete that is 
failing.

I've already worked around it on my end (lazy=False seems of little use 
here, and was being added programatically, so I adjusted it there and it 
seems okay), but I figured I'd point it out as the behavior changed pretty 
radically between those 2 versions.

-- 
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.


Reply via email to