File tree 2 files changed +17
-1
lines changed
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(
168
168
169
169
170
170
def _validate_port_spec (hosts , port ):
171
- if isinstance (port , list ):
171
+ if isinstance (port , list ) and len ( port ) > 1 :
172
172
# If there is a list of ports, its length must
173
173
# match that of the host list.
174
174
if len (port ) != len (hosts ):
175
175
raise exceptions .ClientConfigurationError (
176
176
'could not match {} port numbers to {} hosts' .format (
177
177
len (port ), len (hosts )))
178
+ elif isinstance (port , list ) and len (port ) == 1 :
179
+ port = [port [0 ] for _ in range (len (hosts ))]
178
180
else :
179
181
port = [port for _ in range (len (hosts ))]
180
182
Original file line number Diff line number Diff line change @@ -1088,6 +1088,20 @@ class TestConnectParams(tb.TestCase):
1088
1088
}
1089
1089
)
1090
1090
},
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
+ },
1091
1105
]
1092
1106
1093
1107
@contextlib .contextmanager
You can’t perform that action at this time.
0 commit comments