From: Mike Bayer Date: Sun, 4 Dec 2011 19:28:57 +0000 (-0500) Subject: - [bug] __table_args__ can now be passed as X-Git-Tag: rel_0_7_4~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f68a3a52729ff9b3eee0939292415fd81d61443;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [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. --- diff --git a/CHANGES b/CHANGES index af6e748900..6253467b0a 100644 --- 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] diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 1f082adf14..ffbdfaae99 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -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: diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 9157bf2a4c..2e2989a646 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -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))