Is this a bug or am I doing something wrong? $ cat testordlist.py ; python testordlist.py
import sqlalchemy as sql from sqlalchemy import orm from sqlalchemy.ext.orderinglist import ordering_list from sqlalchemy.ext.declarative import declarative_base engine = sql.create_engine("sqlite:///:memory:") metadata = sql.MetaData(bind=engine) db = orm.create_session(bind=engine) T = declarative_base(metadata=metadata) class A(T): __tablename__ = 'a' id = sql.Column(sql.Integer, primary_key=True) uc = orm.relation('UC', order_by=('i',), cascade='all,delete- orphan') oc = orm.relation('OC', order_by=('i',), cascade='all,delete- orphan', collection_class=ordering_list('i')) class UC(T): __tablename__ = 'uc' a_id = sql.Column(sql.Integer, sql.ForeignKey('a.id'), primary_key=True) i = sql.Column(sql.Integer, primary_key=True) class OC(T): __tablename__ = 'oc' a_id = sql.Column(sql.Integer, sql.ForeignKey('a.id'), primary_key=True) i = sql.Column(sql.Integer, primary_key=True) metadata.create_all() a = A(id=1) a.oc = [OC(), OC()] a.uc = [UC(i=1), UC(i=2)] with db.begin(): db.add(a) with db.begin(): del db.query(A).first().uc[0] with db.begin(): del db.query(A).first().oc[0] Traceback (most recent call last): File "testordlist.py", line 40, in <module> del db.query(A).first().oc[0] File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ session.py", line 449, in __exit__ self.commit() File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ session.py", line 378, in commit self._prepare_impl() File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ session.py", line 362, in _prepare_impl self.session.flush() File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ session.py", line 1354, in flush self._flush(objects) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ session.py", line 1432, in _flush flush_context.execute() File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ unitofwork.py", line 261, in execute UOWExecutor().execute(self, tasks) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ unitofwork.py", line 753, in execute self.execute_save_steps(trans, task) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ unitofwork.py", line 768, in execute_save_steps self.save_objects(trans, task) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/ unitofwork.py", line 759, in save_objects task.mapper._save_obj(task.polymorphic_tosave_objects, trans) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/orm/mapper.py", line 1417, in _save_obj c = connection.execute(statement.values(value_params), params) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/engine/ base.py", line 835, in execute return Connection.executors[c](self, object, multiparams, params) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/engine/ base.py", line 885, in _execute_clauseelement return self.__execute_context(context) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/engine/ base.py", line 907, in __execute_context self._cursor_execute(context.cursor, context.statement, context.parameters[0], context=context) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/engine/ base.py", line 961, in _cursor_execute self._handle_dbapi_exception(e, statement, parameters, cursor, context) File "/home/avdd/tmp/src/sqlalchemy.5/lib/sqlalchemy/engine/ base.py", line 942, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exc.IntegrityError: (IntegrityError) columns a_id, i are not unique u'UPDATE oc SET i=? WHERE oc.a_id = ? AND oc.i = ?' [0, 1, 1] -- 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.