Let me prefix this by saying that I am a newbie to SA, though not to ORMs in general. So far I've really enjoyed using SA: its an amazing package for working with databases.
Presently I am trying to create a GM tool for Shadowrun 4th Edition, where I am trying to model this concept called a "Data Bomb." The Data Bomb works by detonating and doing damage to the hacker and then potentially deleting the file it sits on. There is also some associated metadata that I would like to store, so I have modeled the data bombs as being in a separate table from the files. The database is currently sqlite, but I may switch later to another system that is a little more robust at a later date. The system is MacOS X 10.4.10, Python 2.5.1 Stackless 3.1b3 060516 (python-2.51:55546, May 24 2007, 08:50:09). I am calling the following from inside of a unit test, and no tasklets or threads of any sort are involved in this part of the app. When I attempt to delete an object it generates an exception and then appears to corrupt the session, such that further save statements generate the same exception. These are the table definitions I am presently using: file_table = Table('files', dbutil.metadata, Column('id', Integer, primary_key=True), Column('securable_id', Integer, ForeignKey('securable.id')), Column('node_id', Integer, ForeignKey('nodes.id')), Column('name', String(32), nullable=False), Column('content', String(), nullable=False), Column('version', Integer), Column('encryption', Integer, default=0) ) bomb_table = Table('data_bombs', dbutil.metadata, Column('id', Integer, primary_key=True), Column('name', String(16), default="None"), Column('strength', Integer, CheckConstraint('strength >= 0'), nullable=False), Column('destroy_chance', Float(2), nullable=False), Column('file_id', Integer, ForeignKey('files.id'), unique=True), Column('version', Integer) ) The mapper calls: mapper(DataBomb, bomb_table, version_id_col='version', properties={ 'file':relation(File, backref='bomb') }) mapper(File, file_table, version_id_col='version', inherits=Securable, polymorphic_identity='file', properties={ 'node':relation(node.Node, backref='files', primaryjoin=node.node_table.c.id == file_table.c.node_id) } ) The classes are right now just acting as data stores with a few utility functions. The data bomb takes the file as an argument when it is being created. I have created a DAO for both tables, but for the sake of debugging I have moved the pieces generating the error out into the test function. The DAO uses the "with" statement with begin_nested(). The first unit test that is running: * Creates a file * Creates a data bomb that is associated to that file. * Deletes the data bomb in a separate transaction. The code for the test is as follows: def testBomb(self): session = dbutil.create_session() filetest = file_dao.create('green', 'maho') bomb = bomb_dao.create(filetest, 10) with session.begin(): session.delete(bomb) When it flushes/commits after the deletion, it generates the following: ====================================================================== ERROR: testBomb (nodefile.FileTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/raven/Documents/AoW/workspace/ShadowMatrix/src/ shadowmatrix/model/nodefile.py", line 172, in testBomb session.delete(bomb) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ session.py", line 256, in __exit__ self.commit() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ session.py", line 211, in commit self.session.flush() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ session.py", line 665, in flush self.uow.flush(self, objects) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 202, in flush flush_context.execute() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 414, in execute UOWExecutor().execute(self, head) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1035, in execute self.execute_delete_steps(trans, task) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1056, in execute_delete_steps self.execute_childtasks(trans, task, True) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1070, in execute_childtasks self.execute(trans, child, isdelete) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1035, in execute self.execute_delete_steps(trans, task) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1056, in execute_delete_steps self.execute_childtasks(trans, task, True) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1070, in execute_childtasks self.execute(trans, child, isdelete) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1035, in execute self.execute_delete_steps(trans, task) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1058, in execute_delete_steps self.delete_objects(trans, task) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1041, in delete_objects task.mapper.delete_obj(task.polymorphic_todelete_objects, trans) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ mapper.py", line 1253, in delete_obj params[mapper.version_id_col.key] = mapper.get_attr_by_column(obj, mapper.version_id_col) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ mapper.py", line 949, in get_attr_by_column prop = self._getpropbycolumn(column, raiseerror) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ mapper.py", line 933, in _getpropbycolumn prop = self.columntoproperty[column] File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ util.py", line 101, in __getitem__ return super(TranslatingDict, self).__getitem__(self.__translate_col(col)) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ util.py", line 94, in __translate_col ourcol = self.selectable.corresponding_column(col, keys_ok=False, raiseerr=False) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/sql/ expression.py", line 1605, in corresponding_column for c in column.orig_set: AttributeError: 'str' object has no attribute 'orig_set' The second test that runs just generates the file, retrieves it by name, and then makes sure that name is the same coming out as it is going in: def testCreate(self): file_dao.create('purple', 'foo') filetest = file_dao.get('purple') self.assertEqual(filetest.name, 'purple') After the prior testBomb runs, it generates the following error: ====================================================================== ERROR: testCreate (nodefile.FileTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/raven/Documents/AoW/workspace/ShadowMatrix/src/ shadowmatrix/model/nodefile.py", line 149, in testCreate file_dao.create('purple', 'foo') File "/Users/raven/Documents/AoW/workspace/ShadowMatrix/src/ shadowmatrix/database/dao.py", line 60, in create session.save(obj) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ session.py", line 256, in __exit__ self.commit() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ session.py", line 211, in commit self.session.flush() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ session.py", line 665, in flush self.uow.flush(self, objects) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 202, in flush flush_context.execute() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 414, in execute UOWExecutor().execute(self, head) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1035, in execute self.execute_delete_steps(trans, task) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1056, in execute_delete_steps self.execute_childtasks(trans, task, True) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1070, in execute_childtasks self.execute(trans, child, isdelete) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1035, in execute self.execute_delete_steps(trans, task) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1056, in execute_delete_steps self.execute_childtasks(trans, task, True) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1070, in execute_childtasks self.execute(trans, child, isdelete) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1035, in execute self.execute_delete_steps(trans, task) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1058, in execute_delete_steps self.delete_objects(trans, task) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ unitofwork.py", line 1041, in delete_objects task.mapper.delete_obj(task.polymorphic_todelete_objects, trans) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ mapper.py", line 1253, in delete_obj params[mapper.version_id_col.key] = mapper.get_attr_by_column(obj, mapper.version_id_col) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ mapper.py", line 949, in get_attr_by_column prop = self._getpropbycolumn(column, raiseerror) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ mapper.py", line 933, in _getpropbycolumn prop = self.columntoproperty[column] File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ util.py", line 101, in __getitem__ return super(TranslatingDict, self).__getitem__(self.__translate_col(col)) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/orm/ util.py", line 94, in __translate_col ourcol = self.selectable.corresponding_column(col, keys_ok=False, raiseerr=False) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/site-packages/SQLAlchemy-0.4.0beta4-py2.5.egg/sqlalchemy/sql/ expression.py", line 1605, in corresponding_column for c in column.orig_set: AttributeError: 'str' object has no attribute 'orig_set' If I reverse the order, changing the name of testBomb to testDataBomb, testCreate will run correctly, but testDataBomb will generate the same error as above. testCreate (nodefile.FileTests) ... ok testDataBomb (nodefile.FileTests) ... ERROR Any ideas? Any help is appreciated. Sincerely, David --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---