Correct usage of sorted() in mongodb_user (#46792)

* Correct usage of sorted() in mongodb_user

sorted() can't be called on a list of dicts
without supplying a key parameter. This is
explained really well in the Sorting HOWTO
https://docs.python.org/3.6/howto/sorting.html#key-functions

This commit fixes #46791

* Fix PEP8 issues
This commit is contained in:
Ross Williams 2019-02-13 04:28:35 -05:00 committed by Dag Wieers
parent 21d43e6d94
commit 6e409a91ba

View file

@ -178,6 +178,7 @@ import os
import ssl as ssl_lib
import traceback
from distutils.version import LooseVersion
from operator import itemgetter
try:
from pymongo.errors import ConnectionFailure
@ -319,7 +320,7 @@ def check_if_roles_changed(uinfo, roles, db_name):
roles_as_list_of_dict = make_sure_roles_are_a_list_of_dict(roles, db_name)
uinfo_roles = uinfo.get('roles', [])
if sorted(roles_as_list_of_dict) == sorted(uinfo_roles):
if sorted(roles_as_list_of_dict, key=itemgetter('db')) == sorted(uinfo_roles, key=itemgetter('db')):
return False
return True