From: Mike Bayer Date: Wed, 17 Nov 2010 15:55:10 +0000 (-0500) Subject: - An error is raised if __table_args__ is not in tuple X-Git-Tag: rel_0_7b1~264 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3ca4156495af556e448a8d3f6d5884d08ab2f9b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - An error is raised if __table_args__ is not in tuple or dict format, and is not None. [ticket:1972] --- diff --git a/CHANGES b/CHANGES index c2107364f4..d179b01151 100644 --- a/CHANGES +++ b/CHANGES @@ -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 dd2df63d30..3c6cab59af 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 72e2edf30e..7c8ab0016f 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'