Commits

Mike Bayer  committed 1db1db0

- [bug] Updated warning message when setting
delete-orphan without delete to no longer
refer to 0.6, as we never got around to
upgrading this to an exception. Ideally
this might be better as an exception but
it's not critical either way. [ticket:2325]
- add new test suite to test_cascades for cascade
arguments

  • Participants
  • Parent commits bcac26d

Comments (0)

Files changed (4)

     [ticket:2339].  Thanks to Fayaz Yusuf Khan
     for the patch.
 
+  - [bug] Updated warning message when setting
+    delete-orphan without delete to no longer
+    refer to 0.6, as we never got around to 
+    upgrading this to an exception.  Ideally
+    this might be better as an exception but
+    it's not critical either way.  [ticket:2325]
+
 - sql
    - [bug] related to [ticket:2316], made some 
      adjustments to the change from [ticket:2261]

File lib/sqlalchemy/orm/util.py

 
         if self.delete_orphan and not self.delete:
             util.warn("The 'delete-orphan' cascade option requires "
-                        "'delete'.  This will raise an error in 0.6.")
+                        "'delete'.")
 
         for x in values:
             if x not in all_cascades:

File test/orm/test_cascade.py

 from test.lib import fixtures
 from test.orm import _fixtures
 
+class CascadeArgTest(fixtures.MappedTest):
+    run_inserts = None
+    run_create_tables = None
+    run_deletes = None
+
+    @classmethod
+    def define_tables(cls, metadata):
+        Table('users', metadata,
+              Column('id', Integer, primary_key=True, test_needs_autoincrement=True),
+              Column('name', String(30), nullable=False),
+        )
+        Table('addresses', metadata,
+              Column('id', Integer, primary_key=True, test_needs_autoincrement=True),
+              Column('user_id', Integer, ForeignKey('users.id')),
+              Column('email_address', String(50), nullable=False),
+        )
+
+    @classmethod
+    def setup_classes(cls):
+        class User(cls.Basic):
+            pass
+        class Address(cls.Basic):
+            pass
+
+    def test_delete_orphan_without_delete(self):
+        User, Address = self.classes.User, self.classes.Address
+        users, addresses = self.tables.users, self.tables.addresses
+
+        assert_raises_message(
+            sa_exc.SAWarning,
+            "The 'delete-orphan' cascade option requires 'delete'.",
+            relationship, Address, cascade="save-update, delete-orphan"
+        )
+
+    def test_bad_cascade(self):
+        addresses, Address = self.tables.addresses, self.classes.Address
+
+        mapper(Address, addresses)
+        assert_raises_message(
+            sa_exc.ArgumentError,
+            "Invalid cascade option 'fake'",
+            relationship, Address, cascade="fake, all, delete-orphan"
+        )
+
 
 class O2MCascadeDeleteOrphanTest(fixtures.MappedTest):
     run_inserts = None

File test/orm/test_mapper.py

                           getattr, sa.orm.class_mapper(User), 'properties')
 
 
-    def test_bad_cascade(self):
-        addresses, Address = self.tables.addresses, self.classes.Address
-
-        mapper(Address, addresses)
-        assert_raises(sa.exc.ArgumentError,
-                          relationship, Address, cascade="fake, all, delete-orphan")
-
     def test_friendly_attribute_str_on_uncompiled_boom(self):
         User, users = self.classes.User, self.tables.users