for the benefit of the test.lib.schema package.
- use test.lib.schema.Table for the table within test.lib.fixtures.DeclarativeMappedTest
- [bug] Removed the check for number of
rows affected when doing a multi-delete
against mapped objects. If an ON DELETE
CASCADE exists between two rows, we can't
get an accurate rowcount from the DBAPI;
this particular count is not supported
on most DBAPIs in any case, MySQLdb
is the notable case where it is.
[ticket:2403]
invokes common table expression support
from the Core (see below). [ticket:1859]
+ - [bug] Removed the check for number of
+ rows affected when doing a multi-delete
+ against mapped objects. If an ON DELETE
+ CASCADE exists between two rows, we can't
+ get an accurate rowcount from the DBAPI;
+ this particular count is not supported
+ on most DBAPIs in any case, MySQLdb
+ is the notable case where it is.
+ [ticket:2403]
+
- [bug] Fixed bug whereby objects using
attribute_mapped_collection or
column_mapped_collection could not be
del our_stuff[key]
cols = sorted(cols, key=lambda c:c._creation_order)
table = None
+
+ if hasattr(cls, '__table_cls__'):
+ table_cls = util.unbound_method_to_callable(cls.__table_cls__)
+ else:
+ table_cls = Table
+
if '__table__' not in dict_:
if tablename is not None:
if autoload:
table_kw['autoload'] = True
- cls.__table__ = table = Table(tablename, cls.metadata,
+ cls.__table__ = table = table_cls(tablename, cls.metadata,
*(tuple(cols) + tuple(args)),
**table_kw)
else:
for connection, del_objects in delete.iteritems():
statement = base_mapper._memo(('delete', table), delete_stmt)
- rows = -1
connection = cached_connections[connection]
- if need_version_id and \
- not connection.dialect.supports_sane_multi_rowcount:
+ if need_version_id:
# TODO: need test coverage for this [ticket:1761]
if connection.dialect.supports_sane_rowcount:
rows = 0
for params in del_objects:
c = connection.execute(statement, params)
rows += c.rowcount
+ if rows != len(del_objects):
+ raise orm_exc.StaleDataError(
+ "DELETE statement on table '%s' expected to "
+ "delete %d row(s); %d were matched." %
+ (table.description, len(del_objects), c.rowcount)
+ )
else:
util.warn(
"Dialect %s does not support deleted rowcount "
stacklevel=12)
connection.execute(statement, del_objects)
else:
- c = connection.execute(statement, del_objects)
- if connection.dialect.supports_sane_multi_rowcount:
- rows = c.rowcount
+ connection.execute(statement, del_objects)
- if rows != -1 and rows != len(del_objects):
- raise orm_exc.StaleDataError(
- "DELETE statement on table '%s' expected to "
- "delete %d row(s); %d were matched." %
- (table.description, len(del_objects), c.rowcount)
- )
def _finalize_insert_update_commands(base_mapper, uowtransaction,
states_to_insert, states_to_update):
from test.lib import testing
+from test.lib import schema
from test.lib.testing import adict
from test.lib.engines import drop_all_tables
import sys
cls_registry[classname] = cls
return DeclarativeMeta.__init__(
cls, classname, bases, dict_)
+ class DeclarativeBasic(object):
+ __table_cls__ = schema.Table
_DeclBase = declarative_base(metadata=cls.declarative_meta,
- metaclass=FindFixtureDeclarative)
- class DeclarativeBasic(BasicEntity):
- pass
+ metaclass=FindFixtureDeclarative,
+ cls=DeclarativeBasic)
cls.DeclarativeBasic = _DeclBase
fn()
if cls.declarative_meta.tables:
mapper(MyClass, mytable)
assert_raises(sa.exc.SAWarning, sa.orm.configure_mappers)
+class BatchDeleteIgnoresRowcountTest(fixtures.DeclarativeMappedTest):
+ __requires__ = ('foreign_keys',)
+ @classmethod
+ def setup_classes(cls):
+ class A(cls.DeclarativeBasic):
+ __tablename__ = 'A'
+ __table_args__ = dict(test_needs_fk=True)
+ id = Column(Integer, primary_key=True)
+ parent_id = Column(Integer, ForeignKey('A.id', ondelete='CASCADE'))
+
+ def test_delete_both(self):
+ A = self.classes.A
+ session = Session(testing.db)
+
+ a1, a2 = A(id=1),A(id=2, parent_id=1)
+
+ session.add_all([a1, a2])
+ session.flush()
+
+ session.delete(a1)
+ session.delete(a2)
+
+ # no issue with multi-row count here
+ session.flush()
+
class ExtraPassiveDeletesTest(fixtures.MappedTest):
__requires__ = ('foreign_keys',)