{"id":"e0413b1231c6c902","repo":"sqlalchemy/alembic","slug":"sqlalchemy-1-4-18-required","errorCode":null,"errorMessage":"SQLAlchemy 1.4.18+ required","messagePattern":"SQLAlchemy 1\\.4\\.18\\+ required","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"alembic/operations/base.py","lineNumber":574,"sourceCode":"        This method allows calling async functions from within the\n        synchronous ``upgrade()`` or ``downgrade()`` alembic migration\n        method.\n\n        The async connection passed to the callable shares the same\n        transaction as the connection running in the migration context.\n\n        Any additional arg or kw_arg passed to this function are passed\n        to the provided async function.\n\n        .. versionadded: 1.11\n\n        .. note::\n\n            This method can be called only when alembic is called using\n            an async dialect.\n        \"\"\"\n        if not sqla_compat.sqla_14_18:\n            raise NotImplementedError(\"SQLAlchemy 1.4.18+ required\")\n        sync_conn = self.get_bind()\n        if sync_conn is None:\n            raise NotImplementedError(\"Cannot call run_async in SQL mode\")\n        if not sync_conn.dialect.is_async:\n            raise ValueError(\"Cannot call run_async with a sync engine\")\n        from sqlalchemy.ext.asyncio import AsyncConnection\n        from sqlalchemy.util import await_only\n\n        async_conn = AsyncConnection._retrieve_proxy_for_target(sync_conn)\n        return await_only(async_function(async_conn, *args, **kw_args))\n\n\nclass Operations(AbstractOperations):\n    \"\"\"Define high level migration operations.\n\n    Each operation corresponds to some schema migration operation,\n    executed against a particular :class:`.MigrationContext`\n    which in turn represents connectivity to a database,","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/44fb3450330204b222ff05135e1fbbbdb28c44db/alembic/operations/base.py#L556-L592","documentation":"Operations.run_async relies on SQLAlchemy's AsyncConnection._retrieve_proxy_for_target and await_only, which were added in SQLAlchemy 1.4.18. The guard checks sqla_compat.sqla_14_18 and refuses to proceed on older SQLAlchemy, since the async-bridge APIs do not exist.","triggerScenarios":"Calling op.run_async(some_async_fn) on a project whose installed SQLAlchemy is older than 1.4.18.","commonSituations":"A legacy project pinned to SQLAlchemy 1.3; a CI matrix that accidentally tests against an old SQLAlchemy; an async migration added to a codebase whose dependencies were not bumped.","solutions":["Upgrade SQLAlchemy to 1.4.18 or newer (2.x recommended): pip install -U 'sqlalchemy>=1.4.18'.","Pin SQLAlchemy>=1.4.18 in pyproject.toml / requirements.txt so the dependency resolver enforces it.","Avoid op.run_async and call sync code inside the migration if upgrading is not possible."],"exampleFix":"// before\n# requirements.txt\nsqlalchemy==1.3.24\nop.run_async(seed_async)  # -> NotImplementedError\n// after\n# requirements.txt\nsqlalchemy>=1.4.18","handlingStrategy":"validation","validationCode":"import sqlalchemy\nfrom packaging.version import Version\nif Version(sqlalchemy.__version__) < Version(\"1.4.18\"):\n    raise RuntimeError(\"op.run_async requires SQLAlchemy >= 1.4.18\")","typeGuard":"def supports_run_async() -> bool:\n    import sqlalchemy\n    from packaging.version import Version\n    return Version(sqlalchemy.__version__) >= Version(\"1.4.18\")","tryCatchPattern":null,"preventionTips":["Pin SQLAlchemy>=1.4.18 in project metadata.","Add a dependency check at app startup.","Gate op.run_async behind a version check in shared migration utils."],"tags":["run-async","sqlalchemy-version","dependency"],"analyzedSha":"44fb3450330204b222ff05135e1fbbbdb28c44db","analyzedAt":"2026-08-04T19:57:10.248Z","schemaVersion":2}