From: Mike Bayer Date: Tue, 24 Apr 2012 15:58:14 +0000 (-0400) Subject: - [bug] The warning emitted when using X-Git-Tag: rel_0_8_0b1~464 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2086728eb5c9d25d7e604fc0fc468d5ce5464122;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [bug] The warning emitted when using delete-orphan cascade with one-to-many or many-to-many without single-parent=True is now an error. The ORM would fail to function subsequent to this warning in any case. [ticket:2405] --- diff --git a/CHANGES b/CHANGES index 9e0c43f216..f8bf29317e 100644 --- a/CHANGES +++ b/CHANGES @@ -59,6 +59,13 @@ CHANGES SQL or invoke loader callables/initializers. [ticket:2320] + - [bug] The warning emitted when using + delete-orphan cascade with one-to-many + or many-to-many without single-parent=True + is now an error. The ORM + would fail to function subsequent to this + warning in any case. [ticket:2405] + - [feature] Query now "auto correlates" by default in the same way as select() does. Previously, a Query used as a subquery diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index fd64e7b81b..79676642c5 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -1064,7 +1064,8 @@ class RelationshipProperty(StrategizedProperty): if self.cascade.delete_orphan and not self.single_parent \ and (self.direction is MANYTOMANY or self.direction is MANYTOONE): - util.warn('On %s, delete-orphan cascade is not supported ' + raise sa_exc.ArgumentError( + 'On %s, delete-orphan cascade is not supported ' 'on a many-to-many or many-to-one relationship ' 'when single_parent is not set. Set ' 'single_parent=True on the relationship().' diff --git a/test/orm/test_cascade.py b/test/orm/test_cascade.py index 26ea78da1c..4a20880b65 100644 --- a/test/orm/test_cascade.py +++ b/test/orm/test_cascade.py @@ -4,7 +4,8 @@ from sqlalchemy import Integer, String, ForeignKey, Sequence, \ exc as sa_exc from test.lib.schema import Table, Column from sqlalchemy.orm import mapper, relationship, create_session, \ - sessionmaker, class_mapper, backref, Session, util as orm_util + sessionmaker, class_mapper, backref, Session, util as orm_util,\ + configure_mappers from sqlalchemy.orm import attributes, exc as orm_exc from test.lib import testing from test.lib.testing import eq_ @@ -1725,6 +1726,24 @@ class M2MCascadeTest(fixtures.MappedTest): assert b.count().scalar() == 0 assert a.count().scalar() == 0 + def test_single_parent_error(self): + a, A, B, b, atob = (self.tables.a, + self.classes.A, + self.classes.B, + self.tables.b, + self.tables.atob) + + mapper(A, a, properties={ + 'bs':relationship(B, secondary=atob, + cascade="all, delete-orphan") + }) + mapper(B, b) + assert_raises_message( + sa_exc.ArgumentError, + "On A.bs, delete-orphan cascade is not supported", + configure_mappers + ) + def test_single_parent_raise(self): a, A, B, b, atob = (self.tables.a, self.classes.A,