summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rwxr-xr-xlib/sqlalchemy/ext/declarative.py30
-rw-r--r--test/ext/test_declarative.py16
3 files changed, 26 insertions, 23 deletions
diff --git a/CHANGES b/CHANGES
index 4d4ac726d..9e026e0e9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -43,6 +43,9 @@ CHANGES
and pulled in via name or object ref.
[ticket:2058]
+ - the dictionary at the end of the __table_args__
+ tuple is now optional. [ticket:1468]
+
0.7.0b1
=======
- Detailed descriptions of each change below are
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py
index 00c4aec3f..c8c464d0d 100755
--- a/lib/sqlalchemy/ext/declarative.py
+++ b/lib/sqlalchemy/ext/declarative.py
@@ -262,20 +262,26 @@ dictionary::
__tablename__ = 'sometable'
__table_args__ = {'mysql_engine':'InnoDB'}
-The other, a tuple of the form
-``(arg1, arg2, ..., {kwarg1:value, ...})``, which allows positional
-arguments to be specified as well (usually constraints)::
+The other, a tuple, where each argument is positional
+(usually constraints)::
class MyClass(Base):
__tablename__ = 'sometable'
__table_args__ = (
ForeignKeyConstraint(['id'], ['remote_table.id']),
UniqueConstraint('foo'),
- {'autoload':True}
)
-Note that the keyword parameters dictionary is required in the tuple
-form even if empty.
+Keyword arguments can be specified with the above form by
+specifying the last argument as a dictionary::
+
+ class MyClass(Base):
+ __tablename__ = 'sometable'
+ __table_args__ = (
+ ForeignKeyConstraint(['id'], ['remote_table.id']),
+ UniqueConstraint('foo'),
+ {'autoload':True}
+ )
Using a Hybrid Approach with __table__
=======================================
@@ -1004,14 +1010,10 @@ def _as_declarative(cls, classname, dict_):
if isinstance(table_args, dict):
args, table_kw = (), table_args
elif isinstance(table_args, tuple):
- args = table_args[0:-1]
- table_kw = table_args[-1]
- if len(table_args) < 2 or not isinstance(table_kw, dict):
- raise exc.ArgumentError(
- "Tuple form of __table_args__ is "
- "(arg1, arg2, arg3, ..., {'kw1':val1, "
- "'kw2':val2, ...})"
- )
+ 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 = (), {}
diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py
index 8c97fbf27..12d347f28 100644
--- a/test/ext/test_declarative.py
+++ b/test/ext/test_declarative.py
@@ -672,18 +672,16 @@ class DeclarativeTest(DeclarativeTestBase):
'Mapper Mapper|User|users could not '
'assemble any primary key', define)
- def test_table_args_bad_format(self):
+ def test_table_args_no_dict(self):
- def err():
- class Foo1(Base):
+ class Foo1(Base):
- __tablename__ = 'foo'
- __table_args__ = ForeignKeyConstraint(['id'], ['foo.id'
- ]),
- id = Column('id', Integer, primary_key=True)
+ __tablename__ = 'foo'
+ __table_args__ = ForeignKeyConstraint(['id'], ['foo.bar']),
+ id = Column('id', Integer, primary_key=True)
+ bar = Column('bar', Integer)
- assert_raises_message(sa.exc.ArgumentError,
- 'Tuple form of __table_args__ is ', err)
+ assert Foo1.__table__.c.id.references(Foo1.__table__.c.bar)
def test_table_args_type(self):
def err():