Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
Replace key if not identical to old key in dict#31685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
potiuk commentedMar 4, 2022
Nice :) |
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685
f572737
to4f8c6b6
Compare4f8c6b6
to0fd074a
CompareThank you for first pull request. But we need an issue onbugs.python.org unless the pull request don't change any behavior (e.g. fixing typo, code cleanup). But we are planning to moving issue tracker from bugs.python.org to GitHub issues in this month.
This change is not so easy as you think. In Python, True == 1, False == 0, 2.0 == 2. We guaranteed "first wins" semantics for very long time. So it is not an option to change the dict. I recommend you to start discussion in: Both discussion can be used during issue tracker migration. When posting your idea on the discussion, please describe your use case more concretely. |
ashb commentedMar 7, 2022
@malthe Might be worth turning this in to a doc update to mention this "gotcha" for the next people? |
potiuk commentedMar 7, 2022
Yep. We already asked for ithttps://bugs.python.org/issue46925 and Python maintainers agreed it's a good thing to do and reopened the issue to be "doc-issue". |
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685(cherry picked from commit1949f5d)
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685(cherry picked from commit1949f5d)
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685(cherry picked from commit1949f5d)
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685(cherry picked from commit 1949f5d76b5842d56db91c868ae4655bb7a7689f)GitOrigin-RevId: 91b95ea6633bc14ca9bdefe5eac0ac948465dfc9
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
There is a very probable WeakKeyDict bug in Python standardlibrary (to be confirmed and investigated further) thatmanifests itself in a very rare failure of thetest_stacktrace_on_failure_starts_with_task_execute_methodThis turned out to be related to an unexpected behaviour(and most likely a bug - to be confirmed) of WeakKeyDictwhen you have potentially two different objects with thesame `equals` and `hash` values added to the sameWeakKeyDict as keys.More info on similar report (but raised for a bit differentreason) bug in Python can be found here:https://bugs.python.org/issue44140We submitted a PR to fix the problem foundpython/cpython#31685GitOrigin-RevId: 1949f5d76b5842d56db91c868ae4655bb7a7689f
Uh oh!
There was an error while loading.Please reload this page.
This fixes an issue in
dict
and by extension inweakref.WeakKeyDictionary
which arises when a key that is equal to an existing key is used to set a new value – where the key itself is not replaced.To appreciate this situation, consider when the keys are type
weakref.ref
.In this case, the lifetime of the key after replacing the value is now that of the initial key and not the one that's been set subsequently – since the key entry is still the initial object. If the first key falls to refcount zero, the key is removed from the
weakref.WeakKeyDictionary
– which is unexpected because we have set a newer key which might have refcount greater than zero.In the general case where a value is replaced for the exact same key (object identity), there is no practical difference with this change – and when a new key is used to replace a value, the cost is only a write to memory.
Thanks to@potiuk and@ashb for helping finding this issue which was discovered during flaky test runs inApache Airflow.