{"record":{"id":"51d68d0cba844cf5","repo":"pola-rs/polars","slug":"expected-connection-to-be-a-uri-string-found-qua","errorCode":null,"errorMessage":"expected connection to be a URI string; found {qualified_type_name(uri)!r}","messagePattern":"expected connection to be a URI string; found (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/database/functions.py","lineNumber":496,"sourceCode":"    ...     \"sqlite:///:memory:\",\n    ...     engine=\"adbc\",\n    ...     execute_options={\"parameters\": (30,)},\n    ... )  # doctest: +SKIP\n\n    Or pass multiple parameters:\n\n    >>> df = pl.read_database_uri(\n    ...     \"SELECT * FROM employees WHERE hourly_rate BETWEEN ? AND ?\",\n    ...     \"sqlite:///:memory:\",\n    ...     engine=\"adbc\",\n    ...     execute_options={\"parameters\": (40, 20)},\n    ... )  # doctest: +SKIP\n    \"\"\"\n    from polars.io.database._utils import _read_sql_adbc, _read_sql_connectorx\n\n    if not isinstance(uri, str):\n        msg = f\"expected connection to be a URI string; found {qualified_type_name(uri)!r}\"\n        raise TypeError(msg)\n    elif engine is None:\n        engine = \"connectorx\"\n\n    if engine == \"connectorx\":\n        if execute_options:\n            msg = \"the 'connectorx' engine does not support use of `execute_options`\"\n            raise ValueError(msg)\n        if pre_execution_query:\n            issue_unstable_warning(\n                \"the 'pre-execution-query' parameter is considered unstable.\"\n            )\n        return _read_sql_connectorx(\n            query,\n            connection_uri=uri,\n            partition_on=partition_on,\n            partition_range=partition_range,\n            partition_num=partition_num,\n            protocol=protocol,","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/database/functions.py#L478-L514","documentation":"`read_database_uri` requires `uri` to be a plain string containing one or more connection URIs. Passing any other type (list, bytes, connection object, None) raises TypeError, since only connectorx-style URI strings are accepted.","triggerScenarios":"Calling `read_database_uri(query, [\"postgres://...\"])` (list of URIs), passing a connection object, passing a Path, or passing None as uri.","commonSituations":"Copying DBAPI-style code to the URI API; passing a list of URIs expecting multi-URI load balancing; passing an sqlalchemy Engine object by mistake.","solutions":["Pass a single URI string; connectorx accepts multiple URIs inside one string separated by `|` if supported.","If you have a connection object, use `read_database` instead.","Convert Path/URL objects to str before calling: `str(uri)`."],"exampleFix":"// before\npl.read_database_uri(q, [\"postgresql://u@h/db\"])  # raises\n// after\npl.read_database_uri(q, \"postgresql://u@h/db\")","handlingStrategy":"type-guard","validationCode":"if not isinstance(uri, str):\n    raise TypeError(\"read_database_uri expects a single URI string\")","typeGuard":"def is_uri_string(uri) -> bool:\n    return isinstance(uri, str) and \"://\" in uri","tryCatchPattern":"try:\n    df = pl.read_database_uri(q, uri)\nexcept TypeError as e:\n    if \"URI string\" in str(e):\n        df = pl.read_database_uri(q, str(uri) if not isinstance(uri, (list, dict)) else uri[0])\n    else:\n        raise","preventionTips":["Coerce Path/URL objects with str() before calling","Never pass connection objects to read_database_uri","Validate URI shape at config boundaries with a small guard function"],"tags":["polars","database","uri","type-error"],"backgroundTag":"type-mismatch","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"}