{"record":{"id":"25ca270524bec0fb","repo":"tursodatabase/turso","slug":"tursosyncdialect-does-not-support-host-port-in-url","errorCode":null,"errorMessage":"TursoSyncDialect does not support host/port in URL. The local database path goes after ':///', and remote_url is specified as a query parameter.","messagePattern":"TursoSyncDialect does not support host/port in URL\\. The local database path goes after ':///', and remote_url is specified as a query parameter\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"bindings/python/turso/sqlalchemy/dialect.py","lineNumber":386,"sourceCode":"        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\n\n        client_name = query_params.pop(\"client_name\", None)\n        kwargs[\"client_name\"] = client_name or \"turso-sqlalchemy\"\n\n        long_poll_timeout_ms = query_params.pop(\"long_poll_timeout_ms\", None)","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/python/turso/sqlalchemy/dialect.py#L368-L404","documentation":"The same URL validator used by TursoSyncDialect rejects host and port components. The dialect is file-first: the local database path goes after ':///', and the remote endpoint is supplied as the remote_url query parameter. There is no host to connect to in the URL authority, so any host or port raises ValueError with that explanation.","triggerScenarios":"create_engine('sqlite+turso_sync://localhost:8080/app.db') out of habit from server-database URLs; pasting a libsql:// or https:// endpoint into the SQLAlchemy URL instead of the remote_url parameter.","commonSituations":"Copy-pasting endpoints from libsql-sqlalchemy examples or cloud console connection strings; muscle memory from postgresql://mysql:// URLs.","solutions":["Use the local path form: sqlite+turso_sync:///path/to/local.db","Move the endpoint to a query parameter: ?remote_url=https://your-endpoint","Put the token alongside it as ?auth_token=..."],"exampleFix":"# before\nengine = create_engine(\"sqlite+turso_sync://db.example.com:443/app.db\")\n\n# after\nengine = create_engine(\"sqlite+turso_sync:///app.db?remote_url=https://db.example.com&auth_token=<token>\")","handlingStrategy":"validation","validationCode":"from sqlalchemy.engine.url import make_url\n\nurl = make_url(database_url)\nif url.host or url.port:\n    remote = f\"{url.drivername.split('+')[0]}://{url.host}\"\n    if url.port:\n        remote += f\":{url.port}\"\n    database_url = (\n        f\"sqlite+turso_sync:///{url.database}?remote_url={remote}\"\n    )\nengine = create_engine(database_url)","typeGuard":null,"tryCatchPattern":"try:\n    engine = create_engine(database_url)\nexcept ValueError as e:\n    if \"host/port\" in str(e):\n        raise ValueError(\"Use sqlite+turso_sync:///local.db?remote_url=... instead\") from e\n    raise","preventionTips":["Memorize the shape: sqlite+turso_sync:///local.db?remote_url=...&auth_token=...","Never paste libsql:// or https:// endpoints into the SQLAlchemy URL body","Centralize URL construction in one config function and test it"],"tags":["sqlalchemy","connection-url","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"}