patch: allow empty __table_args__

Issue #2339 resolved
Mike Bayer repo owner created an issue

very easy, with test:

diff -r 896bc4c5b6616492c113d80c1328032413d22b5e lib/sqlalchemy/ext/declarative.py
--- a/lib/sqlalchemy/ext/declarative.py Thu Dec 01 14:21:43 2011 -0500
+++ b/lib/sqlalchemy/ext/declarative.py Sat Dec 03 15:05:39 2011 +0530
@@ -1153,15 +1153,15 @@
     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](-1), dict):
-                    args, table_kw = table_args[0:-1](0:-1), table_args[-1](-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](-1), dict):
+                        args, table_kw = table_args[0:-1](0:-1), table_args[-1](-1)
+                    else:
+                        args = table_args

             autoload = dict_.get('__autoload__')
             if autoload:

test:

from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base, declared_attr


Base = declarative_base()


class MyTable(Base):

    __tablename__ = 'table'

    id = Column(Integer, primary_key=True)

    @declared_attr
    def __table_args__(cls):
        return tuple()

Comments (3)

  1. Log in to comment