Bug 38616 - _err2str fails if ldap exception is not a dict
_err2str fails if ldap exception is not a dict
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM (Generic)
UCS 4.0
Other Linux
: P5 normal (vote)
: UCS 4.0-2-errata
Assigned To: Florian Best
Drees Dormann
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2015-05-28 12:36 CEST by Florian Best
Modified: 2015-07-03 14:10 CEST (History)
1 user (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Error handling, External feedback
Max CVSS v3 score:


Attachments
patch (848 bytes, patch)
2015-05-28 12:36 CEST, Florian Best
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2015-05-28 12:36:58 CEST
Created attachment 6926 [details]
patch

We received the following traceback, 4.0-2 errata194 (Walle):

Die Ausführung des Kommandos udm/syntax/choices/info users/user ist fehlgeschlagen:

Traceback (most recent call last):
  File "%PY2.7%/univention/management/console/modules/__init__.py", line 176, in _decorated
    return function(self, request, *args, **kwargs)
  File "%PY2.7%/univention/management/console/modules/decorators.py", line 316, in _response
    result = _multi_response(self, request)
  File "%PY2.7%/univention/management/console/modules/decorators.py", line 460, in _response
    return list(function(self, iterator, *nones))
  File "%PY2.7%/univention/management/console/modules/decorators.py", line 282, in _fake_func
    yield function(self, *args)
  File "%PY2.7%/univention/management/console/modules/udm/__init__.py", line 923, in syntax_choices_info
    return info_syntax_choices(syntax)
  File "%PY2.7%/univention/management/console/modules/udm/udm_ldap.py", line 1315, in info_syntax_choices
    size += len(module.search(filter=filter_s, simple=not syn.use_objects))
  File "%PY2.7%/univention/management/console/modules/udm/udm_ldap.py", line 163, in _decorated
    return func(*args, **kwargs)
  File "%PY2.7%/univention/management/console/modules/udm/udm_ldap.py", line 146, in wrapper_func
    return _func(*args, **kwargs)
  File "%PY2.7%/univention/management/console/modules/udm/udm_ldap.py", line 139, in _func
    ret = func(*args, **kwargs)
  File "%PY2.7%/univention/management/console/modules/udm/udm_ldap.py", line 582, in search
    result = self.module.lookup(None, ldap_connection, filter_s, base=container, superordinate=superordinate, scope=scope, sizelimit=sizelimit)
  File "%PY2.7%/univention/admin/handlers/computers/computer.py", line 175, in lookup
    res.extend( computer.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit) )
  File "%PY2.7%/univention/admin/handlers/computers/memberserver.py", line 721, in lookup
    for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit):
  File "%PY2.7%/univention/admin/uldap.py", line 358, in search
    raise univention.admin.uexceptions.ldapError(_err2str(msg), original_exception=msg)
  File "%PY2.7%/univention/admin/uldap.py", line 82, in _err2str
    msg = ': '.join([str(m) for m in (iarg.get('desc'), iarg.get('info')) if m])
AttributeError: 'str' object has no attribute 'get'

Remark:
Benutzer aufgerufen

I had a quick look into python-ldap. There are some exceptions which doesn't have a dict as argument. Instead exceptions are raised with a string:
./controls/__init__.py:        raise ldap.UNAVAILABLE_CRITICAL_EXTENSION('Received unexpected critical response control with controlType %s' % (repr(controlType)))

./ldapobject.py:        raise ldap.PROTOCOL_ERROR("Wrong OID in extended response! Expected %s, got %s" % (extop_resp_class.responseName,respoid))

./ldapobject.py:      raise NO_UNIQUE_ENTRY('No or non-unique search result for %s' % (repr(filterstr)))

./ldapobject.py:          raise ldap.TIMEOUT(
            "LDAP time limit (%d secs) exceeded." % (timeout)
          )

Attached is a patch which fixes it.
Comment 1 Florian Best univentionstaff 2015-05-28 12:48:00 CEST
python-ldap violates it's own documentation here:
http://python-ldap.org/doc/html/ldap.html#exceptions
Comment 2 Florian Best univentionstaff 2015-05-29 13:42:25 CEST
Previously:
>>> import ldap
>>> from univention.admin.uldap import _err2str
>>> _err2str(ldap.TIMEOUT("LDAP time limit (%d secs) exceeded."))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/univention/admin/uldap.py", line 82, in _err2str
    msg = ': '.join([str(m) for m in (iarg.get('desc'), iarg.get('info')) if m])
AttributeError: 'str' object has no attribute 'get'

Afterwards:
>>> import ldap
>>> from univention.admin.uldap import _err2str
>>> _err2str(ldap.TIMEOUT("LDAP time limit (%d secs) exceeded."))
'LDAP time limit (%d secs) exceeded.'

Fix: svn r60938
YAML: 2015-05-28-univention-directory-manager-modules.yaml
Comment 3 Drees Dormann univentionstaff 2015-06-01 13:23:51 CEST
Fix: OK
YAML: OK
Comment 4 Florian Best univentionstaff 2015-06-05 20:20:06 CEST
Reported again, (from intern/support?), 4.0-2 errata194 (Walle)
Comment 5 Florian Best univentionstaff 2015-06-23 11:32:57 CEST
Reported again, 4.0-2 errata213 (Walle)
Comment 6 Janek Walkenhorst univentionstaff 2015-07-03 14:10:26 CEST
<http://errata.univention.de/ucs/4.0/217.html>