From: Mike Bayer Date: Tue, 2 Jan 2007 03:39:26 +0000 (+0000) Subject: - invalid options sent to 'cascade' string will raise an exception [ticket:406] X-Git-Tag: rel_0_3_4~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bc79c98b7a71bf1c0ee32ab46007bb49d8b3c1f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - invalid options sent to 'cascade' string will raise an exception [ticket:406] --- diff --git a/CHANGES b/CHANGES index 40db6d62ee..34c69872a6 100644 --- 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"]) diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 47b358fb9d..9fe0dc2a23 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -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): diff --git a/test/orm/mapper.py b/test/orm/mapper.py index 4bcaf07cb4..202bf21117 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -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()