]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] __table_args__ can now be passed as
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 4 Dec 2011 19:28:57 +0000 (14:28 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 4 Dec 2011 19:28:57 +0000 (14:28 -0500)
an empty tuple as well as an empty dict.
[ticket:2339].  Thanks to Fayaz Yusuf Khan
for the patch.

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

diff --git a/CHANGES b/CHANGES
index af6e748900f880e3b64fdbfa48af0a3bfed2d8e4..6253467b0aa475cd6c9c03e5aa58fbed7f34b54e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -96,6 +96,11 @@ CHANGES
      single table inheritance joins.  
      [ticket:2328]
 
+  - [bug] __table_args__ can now be passed as 
+    an empty tuple as well as an empty dict.
+    [ticket:2339].  Thanks to Fayaz Yusuf Khan
+    for the patch.
+
 - sql
    - [bug] related to [ticket:2316], made some 
      adjustments to the change from [ticket:2261]
index 1f082adf14ac3359f3e9409069956909abf28359..ffbdfaae993b3f711913921addd0d721566eaa6e 100755 (executable)
@@ -1153,15 +1153,15 @@ def _as_declarative(cls, classname, dict_):
     if '__table__' not in dict_:
         if tablename is not None:
 
-            if isinstance(table_args, dict):
-                args, table_kw = (), table_args
-            elif isinstance(table_args, tuple):
-                if isinstance(table_args[-1], dict):
-                    args, table_kw = table_args[0:-1], table_args[-1]
-                else:
-                    args, table_kw = table_args, {}
-            else:
-                args, table_kw = (), {}
+            args, table_kw = (), {}
+            if table_args:
+                if isinstance(table_args, dict):
+                    table_kw = table_args
+                elif isinstance(table_args, tuple):
+                    if isinstance(table_args[-1], dict):
+                        args, table_kw = table_args[0:-1], table_args[-1]
+                    else:
+                        args = table_args
 
             autoload = dict_.get('__autoload__')
             if autoload:
index 9157bf2a4c823a6f0b2e27aa4d8fb6e01c06cbf1..2e2989a646a94d5335a861ab1b47bd82602bd37a 100644 (file)
@@ -78,6 +78,20 @@ class DeclarativeTest(DeclarativeTestBase):
         assert_raises_message(sa.exc.InvalidRequestError,
                               'does not have a __table__', go)
 
+    def test_table_args_empty_dict(self):
+
+        class MyModel(Base):
+            __tablename__ = 'test'
+            id = Column(Integer, primary_key=True)
+            __table_args__ = {}
+
+    def test_table_args_empty_tuple(self):
+
+        class MyModel(Base):
+            __tablename__ = 'test'
+            id = Column(Integer, primary_key=True)
+            __table_args__ = ()
+
     def test_cant_add_columns(self):
         t = Table('t', Base.metadata, Column('id', Integer,
                   primary_key=True), Column('data', String))