From 42ef049b637784e8ec7e6f2ef9f1f549b709f285 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Mon, 30 Aug 2021 20:17:56 +0200 Subject: [PATCH] Catch error on ldap import --- cps/admin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cps/admin.py b/cps/admin.py index d6a9751b..7d2a1e8b 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -1702,7 +1702,13 @@ def get_updater_status(): def ldap_import_create_user(user, user_data): user_login_field = extract_dynamic_field_from_filter(user, config.config_ldap_user_object) - username = user_data[user_login_field][0].decode('utf-8') + try: + username = user_data[user_login_field][0].decode('utf-8') + except KeyError as ex: + log.error("Failed to extract LDAP user: %s - %s", user, ex) + message = _(u'Failed to extract at least One LDAP User') + return 0, message + # check for duplicate username if ub.session.query(ub.User).filter(func.lower(ub.User.name) == username.lower()).first(): # if ub.session.query(ub.User).filter(ub.User.name == username).first():