-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Fix mogodb backend authentication and add unittests #5527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
nice PR, thanks! seems |
|
Thank you, @duncaneddy @jinuljt. Your fixes work very well for authSource, but unfortunately, there is still some issue if authMechanism is using. Please see the error below. Traceback (most recent call last):
File "D:\GitHub\org\dev\.venv\lib\site-packages\kombu\utils\objects.py", line 42, in __get__
return obj.__dict__[self.__name__]
KeyError: 'collection'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\GitHub\org\dev\.venv\lib\site-packages\kombu\utils\objects.py", line 42, in __get__
return obj.__dict__[self.__name__]
KeyError: 'database'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\user\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\user\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main
run()
File "c:\Users\user\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Program Files\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Program Files\Python37\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Program Files\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "d:\GitHub\org\dev\backend\tests\workertest.py", line 22, in <module>
print('Task finished? ', result.ready())
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\result.py", line 313, in ready
return self.state in self.backend.READY_STATES
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\result.py", line 473, in state
return self._get_task_meta()['status']
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\result.py", line 412, in _get_task_meta
return self._maybe_set_cache(self.backend.get_task_meta(self.id))
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\backends\base.py", line 386, in get_task_meta
meta = self._get_task_meta_for(task_id)
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\backends\mongodb.py", line 206, in _get_task_meta_for
obj = self.collection.find_one({'_id': task_id})
File "D:\GitHub\org\dev\.venv\lib\site-packages\kombu\utils\objects.py", line 44, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\backends\mongodb.py", line 293, in collection
collection = self.database[self.taskmeta_collection]
File "D:\GitHub\org\dev\.venv\lib\site-packages\kombu\utils\objects.py", line 44, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\backends\mongodb.py", line 288, in database
return self._get_database()
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\backends\mongodb.py", line 271, in _get_database
conn = self._get_connection()
File "D:\GitHub\org\dev\.venv\lib\site-packages\celery\backends\mongodb.py", line 161, in _get_connection
self._connection = MongoClient(**conf)
File "D:\GitHub\org\dev\.venv\lib\site-packages\pymongo\mongo_client.py", line 668, in __init__
username, password, dbase, opts)
File "D:\GitHub\org\dev\.venv\lib\site-packages\pymongo\client_options.py", line 151, in __init__
username, password, database, options)
File "D:\GitHub\org\dev\.venv\lib\site-packages\pymongo\client_options.py", line 39, in _parse_credentials
mechanism, source, username, password, options, database)
File "D:\GitHub\org\dev\.venv\lib\site-packages\pymongo\auth.py", line 107, in _build_credentials_tuple
raise ConfigurationError("%s requires a username." % (mech,))
pymongo.errors.ConfigurationError: SCRAM-SHA-256 requires a username.The reason is pymongo.MongoClient requires username keyword argument if authMechanism is using, but only host and options are given in 'celery\backends\mongodb.py'. conf = dict(self.options)
conf['host'] = host
self._connection = MongoClient(**conf)So I'm wondering if we can authenticate username and password with authentication-options while getting connection through calling MongoClient, not db.authenticate. |
Following through on @jinuljt's PR: #4581
Updating unit tests to confirm mongodb backend supports authentication.
This fixes #4454.
Please let me know what else I can do to help complete this PR.