This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

msg 413975 created
issue 46672 nosy, messages edited ok
clear this message

classification
Title: NameError in asyncio.gather when passing a invalid type as an arg with multiple awaitables
Type: Stage: resolved
Components: asyncio Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, miss-islington, norman.lm.fung, onerandomusername, sobolevn, yselivanov
Priority: normal Keywords: patch

Created on 2022-02-07 05:24 by onerandomusername, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31187 merged sobolevn, 2022-02-07 10:20
PR 31440 merged miss-islington, 2022-02-20 10:24
PR 31441 merged asvetlov, 2022-02-20 10:37
Messages (6)
msg412709 - (view) Author: arl (onerandomusername) Date: 2022-02-07 05:24
It is possible to cause a NameError in asyncio.gather if the second presumed coroutine fails the internal type check.


Sample code:

import asyncio
async def main():
    coros = (asyncio.sleep(1), {1: 1})
    await asyncio.gather(*coros)
asyncio.run(main())



Exception in callback gather.<locals>._done_callback(<Task cancell...tasks.py:593>>) at /usr/local/lib/python3.10/asyncio/tasks.py:714
handle: <Handle gather.<locals>._done_callback(<Task cancell...tasks.py:593>>) at /usr/local/lib/python3.10/asyncio/tasks.py:714>
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "<string>", line 4, in main
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 775, in gather
    if arg not in arg_to_fut:
TypeError: unhashable type: 'dict'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 718, in _done_callback
    if outer.done():
NameError: free variable 'outer' referenced before assignment in enclosing scope
Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "<string>", line 4, in main
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 775, in gather
    if arg not in arg_to_fut:
TypeError: unhashable type: 'dict'
msg413578 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-02-20 10:24
New changeset 4ab8167b9c60d1a04b2e3116d0c52db254b68cda by Nikita Sobolev in branch 'main':
bpo-46672: fix `NameError` in `asyncio.gather` if type check fails (GH-31187)
https://github.com/python/cpython/commit/4ab8167b9c60d1a04b2e3116d0c52db254b68cda
msg413585 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-02-20 12:39
New changeset a6116a980c9eae91c2f9af7cbd0a9727e9b887ba by Andrew Svetlov in branch '3.9':
[3.9] bpo-46672: fix `NameError` in `asyncio.gather` if type check fails (GH-31187) (GH-31441)
https://github.com/python/cpython/commit/a6116a980c9eae91c2f9af7cbd0a9727e9b887ba
msg413592 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-02-20 15:29
New changeset f1916cde24053f4c8b6799730666d19474f8dd09 by Miss Islington (bot) in branch '3.10':
bpo-46672: fix `NameError` in `asyncio.gather` if type check fails (GH-31187) (GH-31440)
https://github.com/python/cpython/commit/f1916cde24053f4c8b6799730666d19474f8dd09
msg413975 - (view) Author: Norman Fung (norman.lm.fung) Date: 2022-02-25 11:14
hi there, on this issue : https://bugs.python.org/issue46672

I encountered this problem on 
a) Python 3.8.5
b) asyncio 3.4.3

This fix https://github.com/python/cpython/commit/f1916cde24053f4c8b6799730666d19474f8dd09 is only available python 3.9 or above?
Thanks
msg414191 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-02-28 12:28
Correct. 
3.8 is in security mode.
It doesn't accept regular patches
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90830
2022-02-28 12:28:14asvetlovsetmessages: + msg414191
2022-02-25 11:14:56norman.lm.fungsetnosy: + norman.lm.fung
messages: + msg413975
2022-02-20 15:29:08asvetlovsetmessages: + msg413592
2022-02-20 15:29:03asvetlovsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.9, Python 3.11
2022-02-20 12:39:35asvetlovsetmessages: + msg413585
2022-02-20 10:37:15asvetlovsetpull_requests: + pull_request29572
2022-02-20 10:24:17asvetlovsetmessages: + msg413578
2022-02-20 10:24:09miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request29571
2022-02-07 10:20:11sobolevnsetkeywords: + patch
nosy: + sobolevn

pull_requests: + pull_request29358
stage: patch review
2022-02-07 05:24:45onerandomusernamecreate