As of now, the attached dummy script would fail with an IndexError as 
sqlalchemy is depending on the fact that __table_args__ is a non-empty tuple 
(if it is a tuple in the first place). However, there are some use cases 
(mostly involving mixins and inheritance) where it would be nice to allow a 
class to return an empty tuple instead of a NoneType.

I have attached a trivial patch for sqlalchemy which checks for the boolean 
tautology of the table_args variable before extracting args and table_kw from 
it. And it doesn't seem to break anything.

Looking forward to your feedback.
-- 
Fayaz Yusuf Khan
Cloud developer and architect
Dexetra SS, Bangalore, India
fayaz.yusuf.khan_AT_gmail_DOT_com
fayaz_AT_dexetra_DOT_com
+91-9746-830-823
diff -r 2b66b5abf755 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], 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:
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()

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to