FieldFile should define __hash__
|Reported by:||Graham King||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
FieldFile defines __eq__ to compare on the name field, but does not define __hash__, hence two FieldFile will be equal but have a different hash. Example:
from django.db.models.fields.files import FileField, FieldFile f = FileField(upload_to='dir') ff1 = FieldFile(None, f, 'dir/file.ext') ff2 = FieldFile(None, f, 'dir/file.ext') print 'Equal?', ff1 == ff2 print 'Hashes are equal?', hash(ff1) == hash(ff2)
I suggest adding the following to FieldFile:
def __hash__(self): return hash(self.name)
I haven't attached a patch because the change is only two lines - I'm happy too if requested.
I noticed this because I'm comparing objects in different databases by comparing the hash of each of their fields.