Fix for recusive db hit when get_users_with_perms with attach_perms=True

This is the pull request for resolving #251.