{"record":{"id":"f5889e3a52dc2358","repo":"tursodatabase/turso","slug":"tursosyncdialect-does-not-support-username-passwor","errorCode":null,"errorMessage":"TursoSyncDialect does not support username/password in URL. Use auth_token query parameter or connect_args instead.","messagePattern":"TursoSyncDialect does not support username/password in URL\\. Use auth_token query parameter or connect_args instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"bindings/python/turso/sqlalchemy/dialect.py","lineNumber":381,"sourceCode":"    @classmethod\n    def import_dbapi(cls):\n        \"\"\"Import the turso.sync module as DBAPI.\"\"\"\n        import turso.sync\n\n        return turso.sync\n\n    def connect(self, *cargs, **cparams):\n        \"\"\"Remap sync_url to remote_url for libsql-sqlalchemy compatibility.\"\"\"\n\n        if \"sync_url\" in cparams and \"remote_url\" not in cparams:\n            cparams[\"remote_url\"] = cparams.pop(\"sync_url\")\n        return super().connect(*cargs, **cparams)\n\n    @staticmethod\n    def _validate_sync_url(opts: Dict[str, Any]) -> None:\n        \"\"\"Reject URL components that TursoSyncDialect doesn't support.\"\"\"\n        if opts.get(\"username\") or opts.get(\"password\"):\n            raise ValueError(\n                \"TursoSyncDialect does not support username/password in URL. \"\n                \"Use auth_token query parameter or connect_args instead.\"\n            )\n        if opts.get(\"host\") or opts.get(\"port\"):\n            raise ValueError(\n                \"TursoSyncDialect does not support host/port in URL. \"\n                \"The local database path goes after ':///', and remote_url \"\n                \"is specified as a query parameter.\"\n            )\n\n    @staticmethod\n    def _extract_sync_params(query_params: Dict[str, str]) -> Dict[str, Any]:\n        \"\"\"Extract and convert sync-specific query parameters into kwargs.\"\"\"\n        kwargs: Dict[str, Any] = {}\n\n        auth_token = query_params.pop(\"auth_token\", None)\n        if auth_token:\n            kwargs[\"auth_token\"] = auth_token","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/python/turso/sqlalchemy/dialect.py#L363-L399","documentation":"TursoSyncDialect validates the parsed URL before building connect arguments and rejects any URL that carries a username or password component. Sync credentials are never read from URL userinfo; the token must be supplied as the auth_token query parameter or through connect_args instead.","triggerScenarios":"create_engine('sqlite+turso_sync://user:secret@/local.db') or a DATABASE_URL copied from a Postgres-style service that embeds user:pass in the authority section.","commonSituations":"Reusing a platform-injected DATABASE_URL that always contains credentials; tools that auto-prepend usernames into URLs; moving an app from Postgres to Turso sync without rewriting the URL scheme.","solutions":["Remove user:pass from the URL","Pass the token as a query parameter: sqlite+turso_sync:///local.db?auth_token=<token>","Or pass it via connect_args: create_engine(url, connect_args={'auth_token': token})"],"exampleFix":"# before\nengine = create_engine(\"sqlite+turso_sync://user:pass@/app.db\")\n\n# after\nengine = create_engine(\"sqlite+turso_sync:///app.db?auth_token=<token>\")","handlingStrategy":"validation","validationCode":"from sqlalchemy.engine.url import make_url\n\nurl = make_url(database_url)\nif url.username or url.password:\n    auth_token = url.password or url.username\n    database_url = url.set(username=None, password=None).render_as_string(hide_password=False)\n    database_url += (\"&\" if \"?\" in database_url else \"?\") + f\"auth_token={auth_token}\"\nengine = create_engine(database_url)","typeGuard":null,"tryCatchPattern":"try:\n    engine = create_engine(database_url)\nexcept ValueError as e:\n    if \"username/password\" in str(e):\n        raise ValueError(\"Strip credentials from the URL; pass ?auth_token= instead\") from e\n    raise","preventionTips":["Keep Turso tokens in query parameters or connect_args, never in URL userinfo","Validate DATABASE_URL shape at app startup before create_engine","Rewrite platform-provided credential URLs once, at the configuration layer"],"tags":["sqlalchemy","connection-url","auth","validation"],"backgroundTag":"invalid-connection-url","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}