{"record":{"id":"3553116cdbc1b9ef","repo":"tursodatabase/turso","slug":"pyturso-s-sqlalchemy-dialects-require-sqlalchemy","errorCode":null,"errorMessage":"pyturso's SQLAlchemy dialects require SQLAlchemy >= 2.0.45 (found {sqlalchemy.__version__}). Upgrade with: pip install 'sqlalchemy>=2.0.45'","messagePattern":"pyturso's SQLAlchemy dialects require SQLAlchemy >= 2\\.0\\.45 \\(found (.+?)\\)\\. Upgrade with: pip install 'sqlalchemy>=2\\.0\\.45'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"bindings/python/turso/sqlalchemy/__init__.py","lineNumber":45,"sourceCode":"        sync.pull()  # Pull remote changes\n        result = conn.execute(text(\"SELECT * FROM users\"))\n        conn.commit()\n        sync.push()  # Push local changes\n\"\"\"\n\nimport re\n\nimport sqlalchemy\n\n# SQLAlchemy 2.0.42 first shipped AsyncAdapt_dbapi_module (imported by .dialect),\n# and 2.0.45 fixed SQLite reflection of multiple CHECK constraints, so 2.0.45 is\n# the oldest release the dialects fully work on. This guard must run before\n# importing .dialect, which fails on releases before 2.0.42 with an ImportError\n# about SQLAlchemy internals instead of a clear message.\n_MIN_SQLALCHEMY_VERSION = (2, 0, 45)\n\nif tuple(int(n) for n in re.findall(r\"\\d+\", sqlalchemy.__version__)[:3]) < _MIN_SQLALCHEMY_VERSION:\n    raise ImportError(\n        f\"pyturso's SQLAlchemy dialects require SQLAlchemy >= 2.0.45 \"\n        f\"(found {sqlalchemy.__version__}). Upgrade with: pip install 'sqlalchemy>=2.0.45'\"\n    )\n\nfrom .dialect import (  # noqa: E402\n    AioTursoDialect,\n    TursoDialect,\n    TursoSyncDialect,\n    get_sync_connection,\n)\n\n__all__ = [\n    \"AioTursoDialect\",\n    \"TursoDialect\",\n    \"TursoSyncDialect\",\n    \"get_sync_connection\",\n]\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/bindings/python/turso/sqlalchemy/__init__.py#L27-L63","documentation":"Import-time version guard in turso.sqlalchemy: the dialects need AsyncAdapt_dbapi_module (first shipped in SQLAlchemy 2.0.42, imported by .dialect) and the multiple-CHECK-constraint reflection fix from 2.0.45, so 2.0.45 is the minimum. Importing turso.sqlalchemy (or letting SQLAlchemy load the dialect from a sqlite+turso:// URL) with an older SQLAlchemy raises ImportError with explicit upgrade instructions instead of a confusing ImportError about SQLAlchemy internals.","triggerScenarios":"`import turso.sqlalchemy` or `create_engine(\"sqlite+turso://...\")` in an environment where sqlalchemy < 2.0.45 is installed — e.g. pinned by requirements.txt, locked by Poetry/Pipenv, or bundled by another framework.","commonSituations":"Projects pinning `sqlalchemy==2.0.x` older than 2.0.45; platforms (Airflow, Jupyter, Superset) that ship their own SQLAlchemy; dependency resolvers picking a older version to satisfy another package's constraint.","solutions":["Upgrade: `pip install 'sqlalchemy>=2.0.45'`","If another dependency pins SQLAlchemy lower, upgrade or loosen that pin so both constraints resolve >= 2.0.45","Verify after installing: `python -c \"import sqlalchemy; print(sqlalchemy.__version__)\"`"],"exampleFix":"# before (requirements.txt)\nsqlalchemy==2.0.36\n\n# after\nsqlalchemy>=2.0.45","handlingStrategy":"validation","validationCode":"import sqlalchemy\n\nMIN = (2, 0, 45)\nversion = tuple(int(n) for n in __import__(\"re\").findall(r\"\\d+\", sqlalchemy.__version__)[:3])\nif version < MIN:\n    raise SystemExit(\n        f\"sqlalchemy {sqlalchemy.__version__} too old for turso dialects; \"\n        \"run: pip install 'sqlalchemy>=2.0.45'\"\n    )\nimport turso.sqlalchemy  # now safe","typeGuard":null,"tryCatchPattern":"try:\n    import turso.sqlalchemy  # noqa: F401\nexcept ImportError as e:\n    if \"SQLAlchemy >= 2.0.45\" in str(e):\n        raise SystemExit(str(e))  # surface the actionable upgrade instruction\n    raise","preventionTips":["Pin `sqlalchemy>=2.0.45` in requirements once you adopt turso dialects","Check the installed version in CI before the first import of turso.sqlalchemy","Beware platforms bundling their own SQLAlchemy (Airflow, Jupyter, Superset) — verify, don't assume"],"tags":["python","sqlalchemy","version-mismatch","import","dependency"],"backgroundTag":"dependency-version-mismatch","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}