Commit 702d3992 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

[1.5.x] Fixed #19634 -- Added proper __hash__ methods.

Classes overriding __eq__ need a __hash__ such that equal objects have
the same hash.

Thanks akaariai for the report and regebro for the patch.

Backport of e76147a8 from master.
parent 1742fd08
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ class BaseDatabaseWrapper(object):
    def __ne__(self, other):
        return not self == other

    __hash__ = object.__hash__
    def __hash__(self):
        return hash(self.alias)

    def _commit(self):
        if self.connection is not None:
+2 −1
Original line number Diff line number Diff line
@@ -135,7 +135,8 @@ class Field(object):
            return self.creation_counter < other.creation_counter
        return NotImplemented

    __hash__ = object.__hash__
    def __hash__(self):
        return hash(self.creation_counter)

    def __deepcopy__(self, memodict):
        # We don't have to deepcopy very much here, since most things are not
+0 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ class FieldFile(File):
        return not self.__eq__(other)

    def __hash__(self):
        # Required because we defined a custom __eq__.
        return hash(self.name)

    # The standard File contains most of the necessary properties, but
+2 −1
Original line number Diff line number Diff line
@@ -152,7 +152,8 @@ class BoundMethodWeakref(object):

    __repr__ = __str__

    __hash__ = object.__hash__
    def __hash__(self):
        return hash(self.key)

    def __bool__( self ):
        """Whether we are still a valid reference"""
+2 −1
Original line number Diff line number Diff line
@@ -85,7 +85,8 @@ class Element(object):
            return False
        return True

    __hash__ = object.__hash__
    def __hash__(self):
        return hash((self.name,) + tuple(a for a in self.attributes))

    def __ne__(self, element):
        return not self.__eq__(element)
Loading