Skip to content

Commit

Permalink
Correct usage of sorted() in mongodb_user (ansible#46792)
Browse files Browse the repository at this point in the history
* 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 ansible#46791

* Fix PEP8 issues
  • Loading branch information
overhacked authored and dagwieers committed Feb 13, 2019
1 parent 21d43e6 commit 6e409a9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/ansible/modules/database/mongodb/mongodb_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
import ssl as ssl_lib
import traceback
from distutils.version import LooseVersion
from operator import itemgetter

try:
from pymongo.errors import ConnectionFailure
Expand Down Expand Up @@ -319,7 +320,7 @@ def make_sure_roles_are_a_list_of_dict(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

Expand Down

0 comments on commit 6e409a9

Please sign in to comment.