summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/psycopg.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-08-01 10:29:13 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-08-01 15:21:04 -0400
commitddc326585a5a40d5c5e18444b14022e78751cdbb (patch)
tree08ca4205f3197a8b393eb1fac62d7bf43c3144d6 /lib/sqlalchemy/dialects/postgresql/psycopg.py
parent3ff18812d8d80b2016ceeea98c808a76cae85e48 (diff)
downloadsqlalchemy-ddc326585a5a40d5c5e18444b14022e78751cdbb.tar.gz
repair psycopg2 (and psycopg) multiple hosts format
Fixed issue in psycopg2 dialect where the "multiple hosts" feature implemented for :ticket:`4392`, where multiple ``host:port`` pairs could be passed in the query string as ``?host=host1:port1&host=host2:port2&host=host3:port3`` was not implemented correctly, as it did not propagate the "port" parameter appropriately. Connections that didn't use a different "port" likely worked without issue, and connections that had "port" for some of the entries may have incorrectly passed on that hostname. The format is now corrected to pass hosts/ports appropriately. As part of this change, maintained support for another multihost style that worked unintentionally, which is comma-separated ``?host=h1,h2,h3&port=p1,p2,p3``. This format is more consistent with libpq's query-string format, whereas the previous format is inspired by a different aspect of libpq's URI format but is not quite the same thing. If the two styles are mixed together, an error is raised as this is ambiguous. Fixes: #4392 Change-Id: Ic9cc0b0e6e90725e158d9efe73e042853dd1263f
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg.py b/lib/sqlalchemy/dialects/postgresql/psycopg.py
index 90bae61e1..414976a62 100644
--- a/lib/sqlalchemy/dialects/postgresql/psycopg.py
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg.py
@@ -184,6 +184,7 @@ class PGDialect_psycopg(_PGDialect_common_psycopg):
psycopg_version = (0, 0)
_has_native_hstore = True
+ _psycopg_adapters_map = None
colspecs = util.update_copy(
_PGDialect_common_psycopg.colspecs,
@@ -241,7 +242,8 @@ class PGDialect_psycopg(_PGDialect_common_psycopg):
# see https://github.com/psycopg/psycopg/issues/83
cargs, cparams = super().create_connect_args(url)
- cparams["context"] = self._psycopg_adapters_map
+ if self._psycopg_adapters_map:
+ cparams["context"] = self._psycopg_adapters_map
if self.client_encoding is not None:
cparams["client_encoding"] = self.client_encoding
return cargs, cparams