]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- invalid options sent to 'cascade' string will raise an exception [ticket:406]
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Jan 2007 03:39:26 +0000 (03:39 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Jan 2007 03:39:26 +0000 (03:39 +0000)
CHANGES
lib/sqlalchemy/orm/util.py
test/orm/mapper.py

diff --git a/CHANGES b/CHANGES
index 40db6d62ee16e7a91af223a3cc5f8e0c8dbc46d1..34c69872a6fae7d66ad4cfe2a7ebfcb00ff6926f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,7 @@ main select generated by the Query object.
 largely interchangeable with "ensure" (so says the dictionary), so I'm not 
 completely illiterate, but its definitely sub-optimal to "ensure" which is
 non-ambiguous.
+- invalid options sent to 'cascade' string will raise an exception [ticket:406]
 
 0.3.3
 - string-based FROM clauses fixed, i.e. select(..., from_obj=["sometext"])
index 47b358fb9d3f9357d0842019e79c9a7b2d185c4c..9fe0dc2a237bdf8ce2342c44ba4b4cc37c32b397 100644 (file)
@@ -4,8 +4,9 @@
 # This module is part of SQLAlchemy and is released under
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
-from sqlalchemy import sql, util
+from sqlalchemy import sql, util, exceptions
 
+all_cascades = util.Set(["delete", "delete-orphan", "all", "merge", "expunge", "save-update", "refresh-expire"])
 class CascadeOptions(object):
     """keeps track of the options sent to relation().cascade"""
     def __init__(self, arg=""):
@@ -17,6 +18,11 @@ class CascadeOptions(object):
         self.expunge = "expunge" in values or "all" in values
         # refresh_expire not really implemented as of yet
         #self.refresh_expire = "refresh-expire" in values or "all" in values
+        
+        for x in values:
+            if x not in all_cascades:
+                raise exceptions.ArgumentError("Invalid cascade option '%s'" % x)
+                
     def __contains__(self, item):
         return getattr(self, item.replace("-", "_"), False)
     def __repr__(self):
index 4bcaf07cb4614a57c7ff9ab8a987499e89437388..202bf2111770c1d36ccb8cf40760989c26124a65 100644 (file)
@@ -64,6 +64,14 @@ class MapperTest(MapperSuperTest):
         except exceptions.ArgumentError:
             pass
 
+    def testbadcascade(self):
+        mapper(Address, addresses)
+        try:
+            mapper(User, users, properties={'addresses':relation(Address, cascade="fake, all, delete-orphan")})
+            assert False
+        except exceptions.ArgumentError, e:
+            assert str(e) == "Invalid cascade option 'fake'"
+        
     def testcolumnprefix(self):
         mapper(User, users, column_prefix='_')
         s = create_session()