- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
          gh-140551: Fix dict crash if clear is called at lookup stage
          #140558
        
          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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
    gh-140551: Fix dict crash if clear is called at lookup stage
  
  #140558
              Conversation
        
          
                Misc/NEWS.d/next/Core_and_Builtins/2025-10-24-20-42-33.gh-issue-140551.-9swrl.rst
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | For the following repro: It crashes inside  | 
| For the following repro: It crashes also inside  Both repro tests on Windows 11 on main branch. | 
…e-140551.-9swrl.rst Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
| Another one I found on main: It is aborted with  | 
| 
 Yes, it's expected that  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| I'm not sure if this is the correct solution. If the keys of a dictionary change during a dict lookup, can we trust the result of the lookup (e.g.  Shouldn't it raise an error if the keys of a dict change during a lookup? | 
| I like this error:             PyErr_SetString(PyExc_RuntimeError,
                    "dict mutated during update"); | 
| 
 CPython behavior has been to retry the lookup if the key changes (since Python 2.2, 453163d). I don't think we should change it. | 
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I will let @methane review and merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I'm not expert, but code looks clear and tests seem actual.
| IIUC, iOS problem in CI is unrelated to this PR, see: #140190 (comment) | 
| 
 I created #140702 for test_UnixDatagramServer() timeout. | 
| 
 IIUC, problem is fixed and CI is green. | 
| Thanks @efimov-mikhail for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. | 
| Sorry, @efimov-mikhail and @kumaraditya303, I could not cleanly backport this to   | 
| Sorry, @efimov-mikhail and @kumaraditya303, I could not cleanly backport this to   | 
| Thanks for the merge, @kumaraditya303. | 
…age (python#140558) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
| GH-140743 is a backport of this pull request to the 3.14 branch. | 
…age (python#140558) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
| GH-140744 is a backport of this pull request to the 3.13 branch. | 
| FYI, @kumaraditya303 | 
dictifhash__eq__function has side effects #140551