File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -168,13 +168,15 @@ def _read_password_from_pgpass(
168168
169169
170170def _validate_port_spec (hosts , port ):
171- if isinstance (port , list ):
171+ if isinstance (port , list ) and len ( port ) > 1 :
172172 # If there is a list of ports, its length must
173173 # match that of the host list.
174174 if len (port ) != len (hosts ):
175175 raise exceptions .ClientConfigurationError (
176176 'could not match {} port numbers to {} hosts' .format (
177177 len (port ), len (hosts )))
178+ elif isinstance (port , list ) and len (port ) == 1 :
179+ port = [port [0 ] for _ in range (len (hosts ))]
178180 else :
179181 port = [port for _ in range (len (hosts ))]
180182
Original file line number Diff line number Diff line change @@ -1088,6 +1088,20 @@ class TestConnectParams(tb.TestCase):
10881088 }
10891089 )
10901090 },
1091+ {
1092+ 'name' : 'multi_host_single_port' ,
1093+ 'dsn' : 'postgres:///postgres?host=127.0.0.1,127.0.0.2&port=5432&user=postgres' ,
1094+ 'result' : (
1095+ [
1096+ ('127.0.0.1' , 5432 ),
1097+ ('127.0.0.2' , 5432 )
1098+ ], {
1099+ 'user' : 'postgres' ,
1100+ 'database' : 'postgres' ,
1101+ 'target_session_attrs' : 'any' ,
1102+ }
1103+ )
1104+ },
10911105 ]
10921106
10931107 @contextlib .contextmanager
You can’t perform that action at this time.
0 commit comments