From b9ba720798af7b3401c9eeaf5280cddf04dc7730 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 3 Jun 2021 12:26:19 +0200 Subject: [PATCH] LdapClient: fix get_object_by_dn() and get_object_by_dn() methods when populate cache method return no objects --- mylib/ldap.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mylib/ldap.py b/mylib/ldap.py index 7b97445..4ee1757 100644 --- a/mylib/ldap.py +++ b/mylib/ldap.py @@ -424,6 +424,12 @@ class LdapClient: if not populate_cache_method: return False populate_cache_method() + if type_name not in self._cached_objects: + if warn: + log.warning('No %s found in LDAP', type_name) + else: + log.debug('No %s found in LDAP', type_name) + return None if dn not in self._cached_objects[type_name]: if warn: log.warning('No %s found with DN "%s"', type_name, dn) @@ -443,6 +449,12 @@ class LdapClient: if not populate_cache_method: return False populate_cache_method() + if type_name not in self._cached_objects: + if warn: + log.warning('No %s found in LDAP', type_name) + else: + log.debug('No %s found in LDAP', type_name) + return None matched = dict( (dn, obj) for dn, obj in self._cached_objects[type_name].items()