[issue19542] WeakValueDictionary bug in setdefault()&pop()

Armin Rigo report at bugs.python.org
Sun Nov 10 09:51:04 CET 2013


New submission from Armin Rigo:

WeakValueDictionary.setdefault() contains a bug that shows up in multithreaded situations using reference cycles.  Attached a test case: it is possible for 'setdefault(key, default)' to return None, although None is never put as a value in the dictionary.  (Actually, being a WeakValueDictionary, None is not allowed as a value.)

The reason is that the code in setdefault() ends in "return wr()", but the weakref "wr" might have gone invalid between the time it was fetched from "self.data" and the "wr()" itself, thus returning None.

A similar problem occurs in pop(), leading it to possibly raise KeyError even if it is called with a default argument.

----------
components: Library (Lib)
messages: 202510
nosy: arigo
priority: normal
severity: normal
status: open
title: WeakValueDictionary bug in setdefault()&pop()
versions: Python 2.7, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19542>
_______________________________________


More information about the Python-bugs-list mailing list