#3008 DN objects hash differently depending on case, affects dn's used as dict keys
Closed: Fixed None Opened 11 years ago by jdennis.

Because the attrs & values in DN's, RDN's and AVA's are comparison case-insensitive the hash value between two objects which compare as equal but differ in case must also yield the same hash value. This is critical when these objects are used as a dict key or in a set because dicts and sets use the object's hash value in conjunction with the objects eq method to lookup the object.

The defect is the DN, RDN & AVA objects computed their hash from the case-preserving string representation thus two otherwise equal objects incorrectly yielded different hash values.

The problem manifests itself when one of these objects is used as a key in a dict, for example a dn.

dn1 = DN(('cn', 'Bob'))
dn2 = DN(('cn', 'bob'))

dn1 == dn2 --> True
# Good, objects who differ only in case are equal

hash(dn1) == hash(dn2) --> False
# Error, the hash values should be equal because the objects are equal

d = {}

d[dn1] = x
d[dn2] = y

len(d) --> 2

# This incorrectly yields a dict with 2 entries whose keys are equal.

patch posted (and ACK'ed)

[PATCH 79] Ticket #3008: DN objects hash differently depending on case

Committed to master: 1328f98

Committed to 3.0: 6cad0d0

Moving closed RC1 tickets to Beta 3.

Metadata Update from @jdennis:
- Issue assigned to someone
- Issue set to the milestone: FreeIPA 3.0 Beta 3

7 years ago

Login to comment on this ticket.

Metadata