]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- An error is raised if __table_args__ is not in tuple
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Nov 2010 15:55:10 +0000 (10:55 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Nov 2010 15:55:10 +0000 (10:55 -0500)
or dict format, and is not None.  [ticket:1972]

CHANGES
lib/sqlalchemy/ext/declarative.py
test/ext/test_declarative.py

diff --git a/CHANGES b/CHANGES
index c2107364f494f3e97a28794e1fd585b4a30a95f7..d179b011512016956417768b7364699dcbecf959 100644 (file)
--- 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
 =====
index dd2df63d30265021025c1caf29f1fd97552349d9..3c6cab59af5807b772b66976c513ec484849f811 100755 (executable)
@@ -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:
index 72e2edf30e9a8a9f336ee98263185447f3feea02..7c8ab0016f650f2f706a75b538aefd74eb7f60c2 100644 (file)
@@ -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'