#9786 closed (fixed)
Files (and subclasses) override __eq__ but not __ne__
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
We were trying to compare two model objects using the following function:
def allModelFieldsEqual(a, b):
fields = [f.name for f in a._meta.fields]
for name in fields:
if getattr(a, name) != getattr(b, name):
return False
return True
This fails when the models contain FileFields, because File doesn't implement ne. Confusingly, because it implements eq, the values also compare equal.
(Pdb) !a.largeImage <ImageFieldFile: /images/first-large-image.png> (Pdb) !b.largeImage <ImageFieldFile: /images/first-large-image.png> (Pdb) !a.largeImage == b.largeImage True (Pdb) !a.largeImage != b.largeImage True
It should probably be implemented as:
def __ne__(self, other):
return not self == other
Change History (2)
comment:1 by , 17 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:2 by , 17 years ago
Note:
See TracTickets
for help on using tickets.
Fixed in r9647.