{"record":{"id":"92c784674dd94537","repo":"pola-rs/polars","slug":"unrecognised-connection-type-qualified-type-name","errorCode":null,"errorMessage":"Unrecognised connection type {qualified_type_name(conn)!r}; no 'execute' or 'cursor' method","messagePattern":"Unrecognised connection type (.+?); no 'execute' or 'cursor' method","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/database/_executor.py","lineNumber":472,"sourceCode":"                    return conn\n\n        elif hasattr(conn, \"cursor\"):\n            # connection has a dedicated cursor; prefer over direct execute\n            cursor = (\n                cast(\"Cursor\", cursor()) if callable(cursor := conn.cursor) else cursor\n            )\n            self.can_close_cursor = True\n            return cursor\n\n        elif hasattr(conn, \"execute\"):\n            # can execute directly (given cursor, sqlalchemy connection, etc)\n            return conn\n\n        msg = (\n            f\"Unrecognised connection type {qualified_type_name(conn)!r}; no \"\n            \"'execute' or 'cursor' method\"\n        )\n        raise TypeError(msg)\n\n    def _oracle_arrow_proxy(self) -> OracleCursorProxy | None:\n        \"\"\"Return an Arrow proxy for a SQLAlchemy \"python-oracledb\" connection.\"\"\"\n        if not self._is_alchemy_async(self.cursor):\n            driver_name = getattr(getattr(self.cursor, \"engine\", None), \"driver\", None)\n            if driver_name == \"oracledb\" and OracleCursorProxy.supports_arrow(\n                # note: proxy the established DBAPI connection so the query\n                # is executed in the caller's own session/transaction\n                raw_conn := getattr(\n                    getattr(self.cursor, \"connection\", None), \"driver_connection\", None\n                )\n            ):\n                return OracleCursorProxy(raw_conn)\n        return None\n\n    async def _sqlalchemy_async_execute(self, query: TextClause, **options: Any) -> Any:\n        \"\"\"Execute a query using an async SQLAlchemy connection.\"\"\"\n        is_session = self._is_alchemy_session(self.cursor)","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/database/_executor.py#L454-L490","documentation":"read_database accepts a connection object, SQLAlchemy engine/session, or cursor-like object. _normalise_cursor probes for an 'execute' or 'cursor' method to obtain a usable cursor; if the passed object has neither, it raises TypeError because polars cannot execute the query against it.","triggerScenarios":"Passing an object to pl.read_database(..., connection=...) that is not a DBAPI connection/cursor or SQLAlchemy engine/session/connection — e.g. a raw connection string URL, a closed/pooled object without those methods, or a custom wrapper that forgets to expose execute/cursor.","commonSituations":"Passing a DSN string instead of an established connection; passing a connectorx/odbc handle; wrapping connections in a proxy class without delegating execute/cursor; mixing async drivers with the sync API.","solutions":["Pass a real DBAPI connection, SQLAlchemy Engine, or open cursor object instead of a string or arbitrary object","If using a wrapper/proxy, implement and delegate 'execute' or 'cursor' methods to the underlying connection","Establish the connection first (e.g. engine.connect() or driver.connect(dsn)) before handing it to polars","Use connection_uri= to let polars open the connection itself if you only have a URL"],"exampleFix":"// before\npl.read_database(query, \"postgresql://user:pw@host/db\")\n// after\nimport psycopg2\nconn = psycopg2.connect(\"postgresql://user:pw@host/db\")\npl.read_database(query, conn)\n// or simply\npl.read_database(query, \"postgresql://user:pw@host/db\".replace(...), engine=\"connectorx\")  # via connection_uri param","handlingStrategy":"type-guard","validationCode":"if not (hasattr(conn, \"execute\") or hasattr(conn, \"cursor\")):\n    raise TypeError(\"connection must be a DBAPI connection/cursor or SQLAlchemy engine/session\")","typeGuard":"def is_supported_connection(conn) -> bool:\n    return callable(getattr(conn, \"execute\", None)) or callable(getattr(conn, \"cursor\", None))","tryCatchPattern":"try:\n    df = pl.read_database(query, conn)\nexcept TypeError as e:\n    if \"Unrecognised connection type\" in str(e):\n        conn = engine.connect()  # open a real connection\n        df = pl.read_database(query, conn)","preventionTips":["Never pass DSN strings as the connection object unless using connection_uri/engine params","Wrap connections only with proxies that delegate execute/cursor","Match sync/async driver APIs to the corresponding polars call"],"tags":["database","type-error","connection","polars"],"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"}