]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] The warning emitted when using
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Apr 2012 15:58:14 +0000 (11:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Apr 2012 15:58:14 +0000 (11:58 -0400)
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]

CHANGES
lib/sqlalchemy/orm/properties.py
test/orm/test_cascade.py

diff --git a/CHANGES b/CHANGES
index 9e0c43f21628e2b44e71e874f5ee7b07d7e64644..f8bf29317e8737bdc0e8f0d5792b71db9c143204 100644 (file)
--- 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
index fd64e7b81b9a579a85770a8c79575a62f382d78b..79676642c5f78cbf5eb2af7fccb9b902f94f91c8 100644 (file)
@@ -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().'
index 26ea78da1c9774fa8aeea7ec19d7d092c58c00a3..4a20880b65ad8fd6924ae583a78ceb6786a2d5d5 100644 (file)
@@ -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,