Commit 5e90cca6 authored by Julian Andres Klode's avatar Julian Andres Klode

Do not override __hash__ in apt.package.Package

We do not override __eq__ so there's not much point overriding __hash__,
and it actively breaks stuff: With cache reopening, the id of a package
object can change, meaning that if you build a set of packages (p_set), then
reopen, you might find that any(p not in p_set for p in p_set).

LP: #1780099
parent ee2e061e
Pipeline #12472 failed with stages
in 8 minutes and 55 seconds
......@@ -1119,13 +1119,6 @@ class Package(object):
This can be used eg. to store additional information about the pkg."""
return self._pkg.id
def __hash__(self):
# type: () -> int
"""Return the hash of the object.
This returns the same value as ID, which is unique."""
return self._pkg.id
@property
def essential(self):
# type: () -> bool
......
......@@ -350,6 +350,8 @@ class TestAptCache(testcommon.TestCase):
c = apt.Cache()
p = c["a"]
a_id = p.id
p_hash = hash(p)
set_of_p = set([p])
self.write_status_file("baz")
apt_pkg.init_system()
c.open()
......@@ -360,6 +362,11 @@ class TestAptCache(testcommon.TestCase):
p.mark_delete()
self.assertEqual([p], c.get_changes())
# Ensure that p can still be found in a set of it, as a test
# for bug https://bugs.launchpad.net/bugs/1780099
self.assertEqual(hash(p), p_hash)
self.assertIn(p, set_of_p)
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment