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

Fix __iter__ yielding different Packages than __getitem__

This fixes a regression introduced in the optimizations in alpha2.

Regression-Of: 78421036
parent a798b617
......@@ -291,7 +291,7 @@ class Cache(object):
.. versionadded:: 1.0.0
fullname = rawpkg.get_fullname(pretty=False)
fullname = rawpkg.get_fullname(pretty=True)
return self._weakref.setdefault(fullname, Package(self, rawpkg))
......@@ -367,6 +367,25 @@ class TestAptCache(testcommon.TestCase):
self.assertEqual(hash(p), p_hash)
self.assertIn(p, set_of_p)
def test_apt_cache_iteration_safe(self):
"""Check that iterating does not produce different results.
This failed in 1.7.0~alpha2, because one part of the code
looked up packages in the weak dict using the pretty name,
and the other using the full name."""
with tempfile.NamedTemporaryFile() as status:
apt_pkg.config["Dir::Etc::SourceList"] = "/dev/null"
apt_pkg.config["Dir::Etc::SourceParts"] = "/dev/null"
apt_pkg.config["Dir::State::Status"] =
c = apt.Cache()
self.assertEqual([c["a"]], [p for p in c if p.marked_delete])
if __name__ == "__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