{"record":{"id":"0ae3f520d0c5291f","repo":"pola-rs/polars","slug":"string-uri-is-invalid-here-call-read-database-ur","errorCode":null,"errorMessage":"string URI is invalid here; call `read_database_uri` instead","messagePattern":"string URI is invalid here; call `read_database_uri` instead","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/database/functions.py","lineNumber":257,"sourceCode":"    ...         query=\"SELECT * FROM test\",\n    ...         url=\"http://localhost:8000\",\n    ...     )\n    ... )  # doctest: +SKIP\n\n    \"\"\"  # noqa: W505\n    if isinstance(connection, str):\n        # check for odbc connection string\n        if re.search(r\"\\bdriver\\s*=\\s*{[^}]+?}\", connection, re.IGNORECASE):\n            _ = import_optional(\n                module_name=\"arrow_odbc\",\n                err_prefix=\"use of ODBC connection string requires the\",\n                err_suffix=\"package\",\n            )\n            connection = ODBCCursorProxy(connection)\n        elif \"://\" in connection:\n            # otherwise looks like a mistaken call to read_database_uri\n            msg = \"string URI is invalid here; call `read_database_uri` instead\"\n            raise ValueError(msg)\n        else:\n            msg = \"unable to identify string connection as valid ODBC (no driver)\"\n            raise ValueError(msg)\n\n    # adbc_driver_manager must be >= 1.7.0 to support passing Python sequences into\n    # parameterised queries (via execute_options) without PyArrow installed\n    if (\n        execute_options is not None\n        and not _PYARROW_AVAILABLE\n        and type(connection).__module__.split(\".\", 1)[0].startswith(\"adbc\")\n    ):\n        adbc_version_no_pyarrow_required = \"1.7.0\"\n        adbc_driver_manager = import_optional(\"adbc_driver_manager\")\n        adbc_str_version = getattr(adbc_driver_manager, \"__version__\", \"0.0\")\n        if not parse_version(adbc_str_version) >= parse_version(\n            adbc_version_no_pyarrow_required\n        ):\n            msg = (","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/database/functions.py#L239-L275","documentation":"`read_database` expects a live DBAPI connection object (or an sqlalchemy/adbc connection), not a connection-string URI. If the `connection` argument is a string containing \"://\", polars assumes you meant `read_database_uri` and raises ValueError to redirect you.","triggerScenarios":"Calling `read_database(query, \"postgresql://user:pass@host/db\")` — a URI string passed where a connection object is required.","commonSituations":"Copy-paste from read_database_uri examples; confusion between the two APIs; code refactored from URI-based to connection-based querying.","solutions":["Call `read_database_uri(query, uri)` instead for URI strings.","Or open a real connection first (e.g. `conn = sqlite3.connect(path)` or an sqlalchemy engine) and pass that to read_database.","For sqlalchemy, pass `engine.connect()` / the engine with the right dialect, not its URL."],"exampleFix":"// before\npl.read_database(\"SELECT * FROM t\", \"postgresql://user@host/db\")  # raises\n// after\npl.read_database_uri(\"SELECT * FROM t\", \"postgresql://user@host/db\")","handlingStrategy":"type-guard","validationCode":"if isinstance(connection, str):\n    raise TypeError(\"read_database needs a connection object; use read_database_uri for URI strings\")","typeGuard":"def is_dbapi_connection(conn) -> bool:\n    return not isinstance(conn, str) and hasattr(conn, \"cursor\")","tryCatchPattern":"try:\n    df = pl.read_database(q, connection)\nexcept ValueError as e:\n    if \"read_database_uri\" in str(e):\n        df = pl.read_database_uri(q, connection)\n    else:\n        raise","preventionTips":["Remember the API split: strings -> read_database_uri, objects -> read_database","Add an assert not isinstance(connection, str) in wrappers around read_database","When refactoring from URI to connection APIs, update call sites together"],"tags":["polars","database","uri","api-misuse"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}