Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed

Conversation

malthe
Copy link

@malthemalthe commentedMar 4, 2022
edited
Loading

This fixes an issue indict 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 typeweakref.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 theweakref.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.

potiuk and arhadthedev reacted with thumbs up emojipotiuk reacted with rocket emojipotiuk reacted with eyes emoji
@potiuk
Copy link

Nice :)

potiuk added a commit to apache/airflow that referenced this pull requestMar 4, 2022
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
@malthemaltheforce-pushed thefix-weakref-key-replacement branch fromf572737 to4f8c6b6CompareMarch 4, 2022 23:10
@malthemalthe changed the titleKeys should always be replaced in WeakKeyDictionaryReplace key if not identical to old key in dictMar 4, 2022
@malthemaltheforce-pushed thefix-weakref-key-replacement branch from4f8c6b6 to0fd074aCompareMarch 4, 2022 23:20
@methane
Copy link
Member

Thank 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.
https://discuss.python.org/t/github-issues-migration-is-coming-soon/13791

  • All issues are copied to the GitHub issues.
  • During the migration (3-5 days estimated), you can not use both of bugs.python.org and GitHub issues.
  • If you don't want to learn bugs.python.org only for few days, I recommend to wait the migration finished.

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.

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
Copy link

ashb commentedMar 7, 2022

@malthe Might be worth turning this in to a doc update to mention this "gotcha" for the next people?

@potiuk
Copy link

@malthe Might be worth turning this in to a doc update to mention this "gotcha" for the next people?

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".

ephraimbuddy pushed a commit to apache/airflow that referenced this pull requestMar 23, 2022
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)
ephraimbuddy pushed a commit to apache/airflow that referenced this pull requestMar 24, 2022
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)
ephraimbuddy pushed a commit to apache/airflow that referenced this pull requestMar 26, 2022
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)
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestJun 4, 2022
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
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestJul 10, 2022
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
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestAug 30, 2022
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
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestOct 4, 2022
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
aglipska pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestOct 7, 2022
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
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestDec 7, 2022
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
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestJan 27, 2023
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
kosteev pushed a commit to kosteev/composer-airflow-test-copybara that referenced this pull requestSep 12, 2024
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
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestSep 17, 2024
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
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestNov 7, 2024
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
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestMay 2, 2025
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
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull requestMay 23, 2025
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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@methanemethaneAwaiting requested review from methanemethane is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@malthe@potiuk@methane@ashb@rhettinger@the-knights-who-say-ni@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp