From 95416623b35bd6d54fabc8f7ea0108ca63c3bc11 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 18 Feb 2020 10:13:05 +0100 Subject: [PATCH] sources/ldap: better handle property mapping evaluation errors --- passbook/sources/ldap/connector.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/passbook/sources/ldap/connector.py b/passbook/sources/ldap/connector.py index dc33c53e4..bc724d3ae 100644 --- a/passbook/sources/ldap/connector.py +++ b/passbook/sources/ldap/connector.py @@ -5,8 +5,9 @@ import ldap3 import ldap3.core.exceptions from structlog import get_logger +from passbook.core.exceptions import PropertyMappingExpressionException from passbook.core.models import Group, User -from passbook.sources.ldap.models import LDAPSource, LDAPPropertyMapping +from passbook.sources.ldap.models import LDAPPropertyMapping, LDAPSource LOGGER = get_logger() @@ -155,9 +156,13 @@ class Connector: properties = {"attributes": {}} for mapping in self._source.property_mappings.all().select_subclasses(): mapping: LDAPPropertyMapping - properties[mapping.object_field] = mapping.evaluate( - user=None, request=None, ldap=attributes - ) + try: + properties[mapping.object_field] = mapping.evaluate( + user=None, request=None, ldap=attributes + ) + except PropertyMappingExpressionException as exc: + LOGGER.warning(exc) + continue if self._source.object_uniqueness_field in attributes: properties["attributes"]["ldap_uniq"] = attributes.get( self._source.object_uniqueness_field