diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-17 10:55:10 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-17 10:55:10 -0500 |
commit | d3ca4156495af556e448a8d3f6d5884d08ab2f9b (patch) | |
tree | ab1ed2c1097595b3edf228c5297d3cff5ab8b6d1 | |
parent | c5ccedfdfd65ddbbc51779c92e6978b0b2123175 (diff) | |
download | sqlalchemy-d3ca4156495af556e448a8d3f6d5884d08ab2f9b.tar.gz |
- An error is raised if __table_args__ is not in tuple
or dict format, and is not None. [ticket:1972]
-rw-r--r-- | CHANGES | 4 | ||||
-rwxr-xr-x | lib/sqlalchemy/ext/declarative.py | 4 | ||||
-rw-r--r-- | test/ext/test_declarative.py | 32 |
3 files changed, 39 insertions, 1 deletions
@@ -59,6 +59,10 @@ CHANGES that includes a remote schema to a *different* schema than that of the parent table doesn't render at all, as cross-schema references do not appear to be supported. + +- declarative + - An error is raised if __table_args__ is not in tuple + or dict format, and is not None. [ticket:1972] 0.6.5 ===== diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index dd2df63d3..3c6cab59a 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -999,6 +999,10 @@ def _as_declarative(cls, classname, dict_): isinstance(obj, declarative_props) ): table_args = cls.__table_args__ + if not isinstance(table_args, (tuple, dict, type(None))): + raise exceptions.ArgumentError( + "__table_args__ value must be a tuple, " + "dict, or None") if base is not cls: inherited_table_args = True elif class_mapped: diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 72e2edf30..7c8ab0016 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -631,7 +631,7 @@ class DeclarativeTest(DeclarativeTestBase): 'Mapper Mapper|User|users could not ' 'assemble any primary key', define) - def test_table_args(self): + def test_table_args_bad_format(self): def err(): class Foo1(Base): @@ -643,7 +643,30 @@ class DeclarativeTest(DeclarativeTestBase): assert_raises_message(sa.exc.ArgumentError, 'Tuple form of __table_args__ is ', err) + + def test_table_args_type(self): + def err(): + class Foo1(Base): + + __tablename__ = 'foo' + __table_args__ = ForeignKeyConstraint(['id'], ['foo.id' + ]) + id = Column('id', Integer, primary_key=True) + assert_raises_message(sa.exc.ArgumentError, + '__table_args__ value must be a tuple, ', err) + + def test_table_args_none(self): + + class Foo2(Base): + __tablename__ = 'foo' + __table_args__ = None + id = Column('id', Integer, primary_key=True) + + assert Foo2.__table__.kwargs == {} + + def test_table_args_dict_format(self): + class Foo2(Base): __tablename__ = 'foo' @@ -652,6 +675,13 @@ class DeclarativeTest(DeclarativeTestBase): assert Foo2.__table__.kwargs['mysql_engine'] == 'InnoDB' + def test_table_args_tuple_format(self): + class Foo2(Base): + + __tablename__ = 'foo' + __table_args__ = {'mysql_engine': 'InnoDB'} + id = Column('id', Integer, primary_key=True) + class Bar(Base): __tablename__ = 'bar' |