Skip to content

Problem when formatting a request encapsulated in a task #590

Closed
@Insoleet

Description

Hello,

The following unit test shows the bug, based on the API available in test_web_functional

    def test_format_task_get(self):

        @asyncio.coroutine
        def handler(request):
            body = yield from request.read()
            self.assertEqual(b'', body)
            return web.Response(body=b'OK')

        @asyncio.coroutine
        def go():
            _, srv, url = yield from self.create_server('GET', '/', handler)
            client = ClientSession(loop=self.loop)
            task = self.loop.create_task(client.get(url))
            self.assertEqual("{}".format(task)[:18], "<Task pending coro")
        self.loop.run_until_complete(go())
Exception in default exception handler
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/coroutines.py", line 270, in _format_coroutine
    coro_code = coro.gi_code
AttributeError: '_RequestContextManager' object has no attribute 'gi_code'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/base_events.py", line 1057, in call_exception_handler
    self.default_exception_handler(context)
  File "/usr/lib/python3.5/asyncio/base_events.py", line 1031, in default_exception_handler
    value = repr(value)
  File "/usr/lib/python3.5/asyncio/futures.py", line 194, in __repr__
    info = self._repr_info()
  File "/usr/lib/python3.5/asyncio/tasks.py", line 102, in _repr_info
    coro = coroutines._format_coroutine(self._coro)
  File "/usr/lib/python3.5/asyncio/coroutines.py", line 272, in _format_coroutine
    coro_code = coro.cr_code
AttributeError: '_RequestContextManager' object has no attribute 'cr_code'

We discovered this bug because quamash formats the task in debug logs ( harvimt/quamash#50 )

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions