Univention Bugzilla – Bug 50053
fix simpleLdap.__setitem__() side effects
Last modified: 2019-09-26 16:12:36 CEST
univention.admin.simeLdap.__setitem__() has some unwanted behavior: 1. For properties which cannot be modified, it raises univention.admin.uexceptions.valueMayNotChange but even if the value is equal to the currently set value. When fixing this, please note, that the comparision for equality needs to be done after syntax.parse() which may normalize the format! >>> o['unlockTime'] = o['unlockTime'] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 396, in __setitem__ raise univention.admin.uexceptions.valueMayNotChange(_('key=%(key)s old=%(old)s new=%(new)s') % {'key': key, 'old': self[key], 'new': value}) univention.admin.uexceptions.valueMayNotChange: key=unlockTime old=None new=None 2. When setting a property to an equal value, it just doesn't replace it. This is evil for lists: >>> obj['foo'] ['bar'] >>> l = ['bar'] >>> obj['foo'] = l >>> l.append('blub') >>> obj['foo'] ['bar'] 3. If the property is required, setting a value to 0 or another false-ish value causes a univention.admin.uexceptions.valueRequired exception. >>> o['username'] = 0 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 399, in __setitem__ raise univention.admin.uexceptions.valueRequired, _('The property %s is required') % self.descriptions[key].short_description univention.admin.uexceptions.valueRequired: The property User name is required 4. When checking for equality of a multivalue property it compares None == [] (because self.info.get(key) is None and not []). Setting lists works: >>> obj['some_multivalue_property'] = [] Setting None doesn't: >>> o['groups'] = None >>> o.info['groups'] Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'groups' This influences also the handling of self.__no_default. (5. Unsetting a value by setting it to None is not supported by all syntax classes, and therefore sometimes raises TypeError or univention.admin.uexceptions.valueInvalidSyntax). >>> o['roomNumber'] = None Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 414, in __setitem__ raise univention.admin.uexceptions.valueInvalidSyntax(key) univention.admin.uexceptions.valueInvalidSyntax: roomNumber