''' For some reason, when I define my class seems to impact sqlalchemy Below is code where if the "class Formation(Library): pass" line is moved down, it works, but as is, I get the error at the end of this file, raised when the last line runs This seems very odd (and bug like) to me, and I'm searching for an explanation, as well as a way to avoid the problem other than carefully shuffling the order of my code around (which can be impossible in a larger project) I'm very new to sqlalchemy, so its likely I'm missing something conceptually; but I don't know where to look for docs about such an issue. This is the minimized version of my project messily crammed into a single file. Any insight would be greatly appreciated.
Thanks, -Craig sqlalchemy 0.6.1 Mac osx 10.5.8, python 2.6.5, intel CPU ''' from sqlalchemy import create_engine engine = create_engine('sqlite:///test.db', echo=False) from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey from sqlalchemy.orm import mapper, relation, create_session, sessionmaker metadata = MetaData() tree_table = Table('tree', metadata, Column('id', Integer, primary_key=True), Column('parent_id', Integer, ForeignKey('tree.id')), Column('name', String), Column('type', String(30), nullable=False), ) class Tree(object): def __init__(self):self.children=[] class Library(Tree): pass lib = Table("Library", metadata,Column('tree_id', Integer, ForeignKey('tree.id'), primary_key=True)) metadata.create_all(engine) mapper(Tree, tree_table, polymorphic_on=tree_table.c.type, polymorphic_identity='Tree', properties={'children':relation(Tree, cascade="all")}) ######### Crash position class Formation(Library): pass mapper(Library, lib, inherits=Tree, polymorphic_identity='Library') ######## No Crash position # class Formation(Library): pass masterLib=Library() sessionmaker(bind=engine)().add(masterLib) masterLib.children.append(Formation()) ''' Traceback (most recent call last): File "main.py", line 38, in <module> masterLib.children.append(x()) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/collections.py", line 930, in append item = __set(self, item, _sa_initiator) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/collections.py", line 905, in __set item = getattr(executor, 'fire_append_event')(item, _sa_initiator) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/collections.py", line 596, in fire_append_event item, initiator) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/attributes.py", line 662, in fire_append_event value = ext.append(state, value, initiator or self) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/unitofwork.py", line 40, in append sess.add(item) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/session.py", line 1058, in add self._save_or_update_state(state) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/session.py", line 1068, in _save_or_update_state self._cascade_save_or_update(state) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/session.py", line 1072, in _cascade_save_or_update 'save-update', state, halt_on=self.__contains__): File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/site-packages/sqlalchemy/orm/session.py", line 1556, in _cascade_unknown_state_iterator for (o, m) in mapper.cascade_iterator(cascade, state, **kwargs): AttributeError: 'NoneType' object has no attribute 'cascade_iterator' ''' -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.