ldap.modlist.modifyModlist() bug?

Michael Ströder michael at stroeder.com
Tue Dec 11 12:25:33 CET 2007


Craig Balfour wrote:
> I've just noticed, however, that when the old and new entry consist of
> the same characters but in a different order (as occurs when initials
> are swapped around, for example) ldap_compare_s() returns
> COMPARE_FALSE but modifyModlist() returns an empty list - the result
> being that nothing gets updated.
> 
> Here's some examples:
> 
> modlist = ldap.modlist.modifyModlist({"givenName": "Fred"}, {"givenName": "Bob"})
> print str(modlist)
> [(1, 'givenName', None), (0, 'givenName', 'Bob')]
> 
> modlist = ldap.modlist.modifyModlist({"givenName": "Fred"}, {"givenName": "derF"})
> print str(modlist)
> []
> 
> Is this a bug in modifyModlist() or a feature? 

This is a bug in *your* code. ;-)
But I also had to look at it twice before recognizing it.

Note that an attribute in the entry's dict is made of an attribute type
and a *list* of attribute values (strings). You're passing in strings as
attribute value lists and the function modifyModlist() iterates over the
single chars in the string instead of iterating over the list items
(attribute values).

So your examples should be (and modifyModlist() works expected):

Python 2.5.1 (r251:54863, Aug  3 2007, 00:52:06)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ldap.modlist import modifyModlist
>>> modifyModlist({"givenName": ["Fred"]}, {"givenName": ["Bob"]})
[(1, 'givenName', None), (0, 'givenName', ['Bob'])]
>>> modifyModlist({"givenName": ["Fred"]}, {"givenName": ["derF"]})
[(1, 'givenName', None), (0, 'givenName', ['derF'])]
>>>

Ciao, Michael.



More information about the python-ldap mailing list