|
1 | 1 | from typing import Dict
|
2 |
| -from urllib.parse import parse_qs, urlparse |
| 2 | +from urllib.parse import parse_qs, urlparse,urlencode,urlunparse |
3 | 3 |
|
4 | 4 | from django.conf import settings
|
5 | 5 | from django.core.exceptions import ImproperlyConfigured
|
@@ -163,15 +163,30 @@ def get_connection_pool(self, params):
|
163 | 163 | # explicitly set service_name and sentinel_manager for the
|
164 | 164 | # SentinelConnectionPool constructor since will be called by from_url
|
165 | 165 | cp_params = dict(params)
|
166 |
| - cp_params.update(service_name=url.hostname, sentinel_manager=self._sentinel) |
167 |
| - pool = super().get_connection_pool(cp_params) |
168 |
| - |
169 | 166 | # convert "is_master" to a boolean if set on the URL, otherwise if not
|
170 | 167 | # provided it defaults to True.
|
171 |
| - is_master = parse_qs(url.query).get("is_master") |
| 168 | + query_params = parse_qs(url.query) |
| 169 | + is_master = query_params.get("is_master") |
172 | 170 | if is_master:
|
173 |
| - pool.is_master = to_bool(is_master[0]) |
| 171 | + cp_params['is_master'] = to_bool(is_master[0]) |
| 172 | + # then remove the "is_master" query string from the URL |
| 173 | + # so it doesn't interfere with the SentinelConnectionPool constructor |
| 174 | + if 'is_master' in query_params: |
| 175 | + del query_params['is_master'] |
| 176 | + new_query = urlencode(query_params, doseq=True) |
| 177 | + |
| 178 | + new_url = urlunparse(( |
| 179 | + url.scheme, |
| 180 | + url.netloc, |
| 181 | + url.path, |
| 182 | + url.params, |
| 183 | + new_query, |
| 184 | + url.fragment |
| 185 | + )) |
| 186 | + |
| 187 | + cp_params.update(service_name=url.hostname, sentinel_manager=self._sentinel,url=new_url) |
174 | 188 |
|
| 189 | + pool = super().get_connection_pool(cp_params) |
175 | 190 | return pool
|
176 | 191 |
|
177 | 192 |
|
|
0 commit comments