1. Peter Sagerson
  2. django-auth-ldap

Issues

Issue #43 resolved

'LDAPSearchUnion' object has no attribute 'search_with_additional_terms' (v1.1.7)

Cybele Wong
created an issue

When setting AUTH_LDAP_GROUP_SEARCH to an LDAPSearchUnion, I get the above error when trying to access user.ldap_user.group_names.

e.g.

AUTH_LDAP_GROUP_SEARCH = LDAPSearchUnion(
                            LDAPSearch("OU=....",ldap.SCOPE_SUBTREE,),
                            LDAPSearch("OU=....",ldap.SCOPE_SUBTREE,),
                            LDAPSearch("OU=....",ldap.SCOPE_SUBTREE,),
                            )
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()

Later on, I try to populate a user and get the LDAP groups as follows, it throws up the 'LDAPSearchUnion' object has no attribute 'search_with_additional_terms' error:

        user = LDAPBackend().populate_user(uid)
        if user is None:
            raise ValidationError(_('No user found with zID %(zid)s'), params={'zid':zid}, code='no_user_found')

        groups = user.ldap_user.group_dns

Fixed the error by adding the following to class LDAPSearchUnion in config.py:

    def search_with_additional_terms(self, term_dict, escape=True):
        new_searchlist = []
        for s in self.searches:
            new_searchlist.append(s.search_with_additional_terms(term_dict, escape=escape))
        return self.__class__(*new_searchlist)

    def search_with_additional_term_string(self, filterstr):
        new_searchlist = []
        for s in self.searches:
            new_searchlist.append(s.search_with_additional_term_string(filterstr))
        return self.__class__(*new_searchlist)

Comments (4)

  1. Log in to comment