Issue 1:
Describe the bug

Traceback (most recent call last):

File "", line 1, in

File "/.../lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 3249, in connect

return self._connection_cls(self)

File "/.../lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 145, in init

self._dbapi_connection = engine.raw_connection()

File "/.../lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 3273, in raw_connection

return self.pool.connect()

File "/.../lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 452, in connect

return _ConnectionFairy._checkout(self)

File "/.../lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 1253, in _checkout

fairy = _ConnectionRecord.checkout(pool)

File "/.../lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 715, in checkout

rec = pool._do_get()

File "/.../lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 169, in _do_get

self._dec_overflow()

File "/.../lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 148, in exit

raise exc_value.with_traceback(exc_tb)

File "/.../lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 166, in _do_get

return self._create_connection()

File "/.../lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 393, in _create_connection

return _ConnectionRecord(self)

File "/.../lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 678, in init

self.__connect()

File "/.../lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 913, in __connect

pool.dispatch.connect.for_modify(

File "/.../lib/python3.8/site-packages/sqlalchemy/event/attr.py", line 473, in _exec_w_sync_on_first_run

self(*args, **kw)

File "/.../lib/python3.8/site-packages/sqlalchemy/event/attr.py", line 487, in call

fn(*args, **kw)

File "/.../lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 1881, in go

return once_fn(*arg, **kw)

File "/.../lib/python3.8/site-packages/sqlalchemy/engine/create.py", line 746, in first_connect

dialect.initialize(c)

File "/.../lib/python3.8/site-packages/sqlalchemy/dialects/postgresql/psycopg.py", line 356, in initialize

info = self._type_info_fetch(connection, "hstore")

File "/.../lib/python3.8/site-packages/sqlalchemy/dialects/postgresql/psycopg.py", line 342, in _type_info_fetch

return TypeInfo.fetch(connection.connection, name)

File "/.../lib/python3.8/site-packages/psycopg/_typeinfo.py", line 86, in fetch

raise TypeError(

TypeError: expected Connection or AsyncConnection, got _AdhocProxiedConnection

To Reproduce

create some new project dir and in dir

$ pipenv install "psycopg[binary]"
$ pipenv install --pre SQLAlchemy

$ docker run --rm --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword postgres

another shell
$ docker exec -it some-postgres bash

$ psql -U postgres

CREATE DATABASE "app-store";
CREATE USER "app-user" WITH ENCRYPTED PASSWORD 'app-password';
GRANT ALL PRIVILEGES ON DATABASE "app-store" TO "app-user";

again in project dir shell

$ pipenv shell
$ python
$ python
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sqlalchemy import create_engine
my import text

engine = create_engine("postgresql+psycopg://app-user:app-password@localhost:5432/app-store")

with engine.connect() as con:
con.execute(text('Select 1;'))>>> from sqlalchemy import text
>>>
>>> engine = create_engine("postgresql+psycopg://app-user:app-password@localhost:5432/app-store")
>>>
>>> with engine.connect() as con:
... con.execute(text('Select 1;'))
...

Error

# Copy complete stack trace and error message here, including SQL log output if applicable.

Versions

OS: Ubuntu 20.04.5 LTS

Python: Python 3.8.10

SQLAlchemy: 2.0.0rc2

Database: PostgreSQL 15.0 (Debian 15.0-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit

DBAPI (eg: psycopg, cx_oracle, mysqlclient): psycopg

Additional context

import psycopg

psycopg.version

'3.1.8'

Issue 2:
looks like 3.1.8 adds a typecheck for TypeInfo.fetch

INTERNALERROR> File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/engine/create.py", line 746, in first_connect
INTERNALERROR> dialect.initialize(c)
INTERNALERROR> File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/dialects/postgresql/psycopg.py", line 356, in initialize
INTERNALERROR> info = self._type_info_fetch(connection, "hstore")
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/dialects/postgresql/psycopg.py", line 342, in _type_info_fetch
INTERNALERROR> return TypeInfo.fetch(connection.connection, name)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/classic/.venv311/lib/python3.11/site-packages/psycopg/_typeinfo.py", line 86, in fetch
INTERNALERROR> raise TypeError(
INTERNALERROR> TypeError: expected Connection or AsyncConnection, got _AdhocProxiedConnection

that's our wrapper so we have to unwrap one more level