ldap: Continue syncing other fields even if a field is missing.

Earlier the behavior was to raise an exception thereby stopping the
whole sync. Now we log an error message and skip the field. Also
fixes the `query_ldap` command to report missing fields without
error.

Fixes: #11780.
This commit is contained in:
Harshit Bansal
2019-03-05 08:40:40 +00:00
committed by Tim Abbott
parent 58d28eed5d
commit 4a9bd89f47
3 changed files with 26 additions and 3 deletions

View File

@@ -347,7 +347,13 @@ class ZulipLDAPAuthBackendBase(ZulipAuthMixin, LDAPBackend):
if not attr.startswith('custom_profile_field__'):
continue
var_name = attr.split('custom_profile_field__')[1]
value = ldap_user.attrs[ldap_attr][0]
try:
value = ldap_user.attrs[ldap_attr][0]
except KeyError:
# If this user doesn't have this field set then ignore this
# field and continue syncing other fields. `django-auth-ldap`
# automatically logs error about missing field.
continue
values_by_var_name[var_name] = value
fields_by_var_name = {} # type: Dict[str, CustomProfileField]