mirror of https://github.com/celery/kombu.git
Fix readpreference option parsing in MongoDB transport (#751)
* Fix readpreference option parsing in MongoDB transport * Update changelog
This commit is contained in:
parent
645bbd3078
commit
ba873ba4f2
11
Changelog
11
Changelog
|
@ -4,6 +4,17 @@
|
||||||
Change history
|
Change history
|
||||||
================
|
================
|
||||||
|
|
||||||
|
.. _version-4.0.3:
|
||||||
|
|
||||||
|
4.0.3
|
||||||
|
=====
|
||||||
|
:release-date: TBA
|
||||||
|
:release-by: Ask Solem
|
||||||
|
|
||||||
|
- MongoDB: Fixed problem with using readPreference option at pymongo 3.x.
|
||||||
|
|
||||||
|
Contributed by **Mikhail Elovskikh**.
|
||||||
|
|
||||||
.. _version-4.0.2:
|
.. _version-4.0.2:
|
||||||
|
|
||||||
4.0.2
|
4.0.2
|
||||||
|
|
|
@ -274,18 +274,21 @@ class Channel(virtual.Channel):
|
||||||
if self.connect_timeout else None),
|
if self.connect_timeout else None),
|
||||||
}
|
}
|
||||||
options.update(parsed['options'])
|
options.update(parsed['options'])
|
||||||
|
options = self._prepare_client_options(options)
|
||||||
|
|
||||||
return hostname, dbname, options
|
return hostname, dbname, options
|
||||||
|
|
||||||
def _prepare_client_options(self, options):
|
def _prepare_client_options(self, options):
|
||||||
if pymongo.version_tuple >= (3,):
|
if pymongo.version_tuple >= (3,):
|
||||||
options.pop('auto_start_request', None)
|
options.pop('auto_start_request', None)
|
||||||
|
if isinstance(options.get('readpreference'), int):
|
||||||
|
modes = pymongo.read_preferences._MONGOS_MODES
|
||||||
|
options['readpreference'] = modes[options['readpreference']]
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def _open(self, scheme='mongodb://'):
|
def _open(self, scheme='mongodb://'):
|
||||||
hostname, dbname, options = self._parse_uri(scheme=scheme)
|
hostname, dbname, conf = self._parse_uri(scheme=scheme)
|
||||||
|
|
||||||
conf = self._prepare_client_options(options)
|
|
||||||
conf['host'] = hostname
|
conf['host'] = hostname
|
||||||
|
|
||||||
env = _detect_environment()
|
env = _detect_environment()
|
||||||
|
|
|
@ -81,6 +81,12 @@ class test_mongodb_uri_parsing:
|
||||||
assert hostname == 'mongodb://foo:bar@localhost/dbname'
|
assert hostname == 'mongodb://foo:bar@localhost/dbname'
|
||||||
assert dbname == 'dbname'
|
assert dbname == 'dbname'
|
||||||
|
|
||||||
|
def test_correct_readpreference(self):
|
||||||
|
url = 'mongodb://localhost/dbname?readpreference=nearest'
|
||||||
|
channel = _create_mock_connection(url).default_channel
|
||||||
|
hostname, dbname, options = channel._parse_uri()
|
||||||
|
assert options['readpreference'] == 'nearest'
|
||||||
|
|
||||||
|
|
||||||
class BaseMongoDBChannelCase:
|
class BaseMongoDBChannelCase:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue