{"id":"8dd956d7b069356c","repo":"sqlalchemy/alembic","slug":"missing-required-positional-argument-s","errorCode":null,"errorMessage":"missing required positional argument: %s","messagePattern":"missing required positional argument: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"alembic/util/langhelpers.py","lineNumber":178,"sourceCode":"                    if oldname in kw:\n                        warnings.warn(\n                            \"Argument %r is now named %r \"\n                            \"for method %s().\" % (oldname, newname, fn_name)\n                        )\n                        return_kw[newname] = kw.pop(oldname)\n                return_kw.update(kw)\n\n                args = list(args)\n                if spec[3]:\n                    pos_only = spec[0][: -len(spec[3])]\n                else:\n                    pos_only = spec[0]\n                for arg in pos_only:\n                    if arg not in return_kw:\n                        try:\n                            return_args.append(args.pop(0))\n                        except IndexError:\n                            raise TypeError(\n                                \"missing required positional argument: %s\"\n                                % arg\n                            )\n                return_args.extend(args)\n\n                return return_args, return_kw\n\n            globals_[\"_translate\"] = translate\n        else:\n            outer_args = \"*args, **kw\"\n            inner_args = \"*args, **kw\"\n            translate_str = \"\"\n\n        func_text = textwrap.dedent(\n            \"\"\"\\\n        def %(name)s(%(args)s):\n            %(doc)r\n            %(translate)s","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/44fb3450330204b222ff05135e1fbbbdb28c44db/alembic/util/langhelpers.py#L160-L196","documentation":"Raised as TypeError inside the translate() closure of ModuleClsProxy._create_method_proxy (langhelpers.py:178) during legacy-argument translation. When a method decorated with @_with_legacy_names is called positionally and a positional slot that maps to a renamed (now keyword) parameter is not supplied, translation runs out of args and reports the missing parameter name. It is effectively a richer TypeError for proxied methods with legacy aliases.","triggerScenarios":"Calling an op.* or Operations method that has _legacy_translations with too few positional arguments, relying on a renamed parameter that the caller omitted. The legacy translation machinery tries to map old positional order to new parameter order and finds a gap.","commonSituations":"Upgrading Alembic and an old code path still calls a method by its pre-rename positional signature; copy-pasted migration snippets from older tutorials that omit a now-required positional argument; calling op methods with keyword names that were renamed (triggers a DeprecationWarning) and simultaneously missing a positional arg.","solutions":["Check the method signature in the current Alembic docs/version and supply the missing positional or use the new keyword name.","Update calls that use deprecated argument names (the DeprecationWarning tells you the new name).","Pin or align your Alembic version with the one the migrations were written for, then migrate the calls.","Pass arguments by keyword to be resilient to positional-order changes."],"exampleFix":"# before (legacy positional, missing arg)\nfrom alembic import op\nop.alter_column('t', 'c', nullable=False)  # missing required renamed arg\n# after: pass by keyword per current signature\nop.alter_column('t', 'c', nullable=False, existing_type=sa.String())","handlingStrategy":"validation","validationCode":"import inspect\nfrom alembic import op\n\ndef check_signature_compatible(meth_name: str, *args, **kwargs):\n    meth = getattr(op, meth_name)\n    sig = inspect.signature(meth)\n    bound = sig.bind_partial(*args, **kwargs)\n    bound.apply_defaults()\n    missing = [p for n, p in sig.parameters.items()\n               if p.default is inspect.Parameter.empty\n               and p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD)\n               and n not in bound.arguments]\n    if missing:\n        raise TypeError(f'{meth_name} missing required args: {missing}')","typeGuard":null,"tryCatchPattern":"try:\n    op.alter_column('t', 'c', existing_type=sa.String())\nexcept TypeError as e:\n    if 'missing required positional argument' in str(e):\n        # consult current signature and supply the missing kwarg\n        raise\n    raise","preventionTips":["Call op methods with keyword arguments to survive positional reordering.","After upgrading Alembic, run a no-op `alembic upgrade head --sql` to surface signature drift.","Address DeprecationWarnings about renamed arguments immediately."],"tags":["alembic","operations","legacy-api","arguments","signature"],"analyzedSha":"44fb3450330204b222ff05135e1fbbbdb28c44db","analyzedAt":"2026-08-04T19:57:10.248Z","schemaVersion":2}