From 4fd02761188764e3b82db36da47127a8dcfb950e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 14 Jul 2015 13:25:18 -0400 Subject: - handle missing arg more clearly - add missing translate for create_pk --- alembic/operations/ops.py | 5 ++++- alembic/util/langhelpers.py | 7 ++++++- tests/test_op.py | 30 ++++++++++++++++++++++++++++++ 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( -- cgit v1.2.1