Skip to content
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

NameError in asyncio.gather when passing a invalid type as an arg with multiple awaitables #90830

Closed
onerandomusername mannequin opened this issue Feb 7, 2022 · 6 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-asyncio

Comments

@onerandomusername
Copy link
Mannequin

onerandomusername mannequin commented Feb 7, 2022

BPO 46672
Nosy @asvetlov, @1st1, @miss-islington, @sobolevn, @onerandomusername
PRs
  • bpo-46672: fix NameError in asyncio.gather if type check fails #31187
  • [3.10] bpo-46672: fix NameError in asyncio.gather if type check fails (GH-31187) #31440
  • [3.9] bpo-46672: fix NameError in asyncio.gather if type check fails (GH-31187) #31441
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-02-20.15:29:03.071>
    created_at = <Date 2022-02-07.05:24:45.795>
    labels = ['3.11', '3.9', '3.10', 'expert-asyncio']
    title = 'NameError in asyncio.gather when passing a invalid type as an arg with multiple awaitables'
    updated_at = <Date 2022-02-28.12:28:14.587>
    user = 'https://github.com/onerandomusername'

    bugs.python.org fields:

    activity = <Date 2022-02-28.12:28:14.587>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-20.15:29:03.071>
    closer = 'asvetlov'
    components = ['asyncio']
    creation = <Date 2022-02-07.05:24:45.795>
    creator = 'onerandomusername'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46672
    keywords = ['patch']
    message_count = 6.0
    messages = ['412709', '413578', '413585', '413592', '413975', '414191']
    nosy_count = 6.0
    nosy_names = ['asvetlov', 'yselivanov', 'miss-islington', 'sobolevn', 'onerandomusername', 'norman.lm.fung']
    pr_nums = ['31187', '31440', '31441']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46672'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @onerandomusername
    Copy link
    Mannequin Author

    onerandomusername mannequin commented Feb 7, 2022

    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'

    @onerandomusername onerandomusername mannequin added 3.10 only security fixes topic-asyncio labels Feb 7, 2022
    @asvetlov
    Copy link
    Contributor

    New changeset 4ab8167 by Nikita Sobolev in branch 'main':
    bpo-46672: fix NameError in asyncio.gather if type check fails (GH-31187)
    4ab8167

    @asvetlov
    Copy link
    Contributor

    New changeset a6116a9 by Andrew Svetlov in branch '3.9':
    [3.9] bpo-46672: fix NameError in asyncio.gather if type check fails (GH-31187) (GH-31441)
    a6116a9

    @asvetlov asvetlov added 3.9 only security fixes 3.11 only security fixes labels Feb 20, 2022
    @asvetlov asvetlov added 3.9 only security fixes 3.11 only security fixes labels Feb 20, 2022
    @asvetlov
    Copy link
    Contributor

    New changeset f1916cd by Miss Islington (bot) in branch '3.10':
    bpo-46672: fix NameError in asyncio.gather if type check fails (GH-31187) (GH-31440)
    f1916cd

    @normanlmfung
    Copy link
    Mannequin

    normanlmfung mannequin commented Feb 25, 2022

    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 f1916cd is only available python 3.9 or above?
    Thanks

    @asvetlov
    Copy link
    Contributor

    Correct.
    3.8 is in security mode.
    It doesn't accept regular patches

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-asyncio
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant