summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-07-14 13:25:18 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-07-14 13:25:18 -0400
commit4fd02761188764e3b82db36da47127a8dcfb950e (patch)
treef6eb78882c77ef8d968812ce83302eca4add8326
parent6f8d0f2e2d119a092bd4c46c42eca2d4737e0d23 (diff)
downloadalembic-4fd02761188764e3b82db36da47127a8dcfb950e.tar.gz
- handle missing arg more clearly
- add missing translate for create_pk
-rw-r--r--alembic/operations/ops.py5
-rw-r--r--alembic/util/langhelpers.py7
-rw-r--r--tests/test_op.py30
3 files changed, 40 insertions, 2 deletions
diff --git a/alembic/operations/ops.py b/alembic/operations/ops.py
index 73ae55f..aee2c90 100644
--- a/alembic/operations/ops.py
+++ b/alembic/operations/ops.py
@@ -150,7 +150,10 @@ class CreatePrimaryKeyOp(AddConstraintOp):
self.columns, schema=self.schema)
@classmethod
- @util._with_legacy_names([('name', 'constraint_name')])
+ @util._with_legacy_names([
+ ('name', 'constraint_name'),
+ ('cols', 'columns')
+ ])
def create_primary_key(
cls, operations,
constraint_name, table_name, columns, schema=None):
diff --git a/alembic/util/langhelpers.py b/alembic/util/langhelpers.py
index 21d2bfb..f25ce67 100644
--- a/alembic/util/langhelpers.py
+++ b/alembic/util/langhelpers.py
@@ -125,7 +125,12 @@ class ModuleClsProxy(with_metaclass(_ModuleClsMeta)):
pos_only = spec[0]
for arg in pos_only:
if arg not in return_kw:
- return_args.append(args.pop(0))
+ try:
+ return_args.append(args.pop(0))
+ except IndexError:
+ raise TypeError(
+ "missing required positional argument: %s"
+ % arg)
return_args.extend(args)
return return_args, return_kw
diff --git a/tests/test_op.py b/tests/test_op.py
index 610c948..396ddf7 100644
--- a/tests/test_op.py
+++ b/tests/test_op.py
@@ -606,6 +606,36 @@ class OpTest(TestBase):
"ALTER TABLE t1 ADD CONSTRAINT uk_test UNIQUE (foo, bar)"
)
+ def test_drop_constraint_legacy_kwarg(self):
+ context = op_fixture()
+ op.drop_constraint(name='pk_name',
+ table_name='sometable',
+ type_='primary')
+ context.assert_(
+ "ALTER TABLE sometable DROP CONSTRAINT pk_name"
+ )
+
+ def test_create_pk_legacy_kwarg(self):
+ context = op_fixture()
+ op.create_primary_key(name=None,
+ table_name='sometable',
+ cols=['router_id', 'l3_agent_id'])
+ context.assert_(
+ "ALTER TABLE sometable ADD PRIMARY KEY (router_id, l3_agent_id)"
+ )
+
+ def test_legacy_kwarg_catches_arg_missing(self):
+ op_fixture()
+
+ assert_raises_message(
+ TypeError,
+ "missing required positional argument: columns",
+ op.create_primary_key,
+ name=None,
+ table_name='sometable',
+ wrong_cols=['router_id', 'l3_agent_id']
+ )
+
def test_add_unique_constraint_schema(self):
context = op_fixture()
op.create_unique_constraint(