-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the use case
A fix will allow sqlalchemy to work with some database servers implemented enough postgres wire protocol but not all the PostgreSQL features assumed by sqlalchemy.
Description
sqlalchemyattempted to use queries in
engine.default.get_server_version_info()
engine.default.._get_default_schema_name()
engine.default..get_default_isolation_level()
and
dialects.postgresql.PGDialect.self._set_backslash_escapes()
to probe and enable features for PostgreSQL and compatible databases. While there are good reasons, they could fail with unhandled errors for database servers that support enough postgres wire protocol and features but otherwise doesn't support these particular functionalities. In particular, sqlalchemy assumed the error would always be NotImplementedError in get_server_version_info() and proceeded to use server_version_info without further check the None condition arise from NotImplementedError. However, for drivers like pg8000, errors like ProgrammingError would be thrown instead. To make sqlalchemy usable for the many different drivers and servers combinations, it is desirable to make sqlalchemy as lenient as possible without detrimental side effects.
Databases / Backends / Drivers targeted
A fix is tested with arcadedb 23.10.1 with pg8000. It is possible this will also fix for other servers implemented enough postgres wire protocols
Example Use
After the fix, the following code works
from sqlalchemy import create_engine
import pandas as pd
engine = create_engine(
'postgresql+pg8000://' + os.environ['DB_USER'] + ':' + os.environ['DB_PASS'] + '@localhost:3333/arcade_testdb', isolation_level="AUTOCOMMIT",
connect_args={'ssl_context': None}
)
df = pd.read_sql_query("select * from schema:database", con=engine)
engine.dispose()
Additional context
No response