Skip to content

Allow caching of middleware construction #10890

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

Dreamsorcerer
Copy link
Member

Just putting this here so we don't forget about it. Feel free to pick it up.

@Dreamsorcerer Dreamsorcerer requested a review from asvetlov as a code owner May 19, 2025 22:34
@Dreamsorcerer Dreamsorcerer added the backport:skip Skip backport bot label May 19, 2025
Comment on lines 246 to 250
response_params: _ResponseParams,
timeout: ClientTimeout,
params: Query = None,
headers: Optional[LooseHeaders] = None,
skip_auto_headers: Optional[Iterable[str]] = None,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just thinking through future maintainability of this class. Should we put in a **kwargs: Any and not use it, so that any subclass is required to include that and pass it through the super() call? That way we should be pretty safe to add parameters in future without worrying about breaking any subclasses.

@Dreamsorcerer
Copy link
Member Author

Dreamsorcerer commented May 19, 2025

@bdraco Does the proxy code have any impact on middlewares? Seems to be a ClientRequest created here with a lot less arguments, just wondering if there's any issue here:

proxy_req = ClientRequest(

Otherwise, I guess that's why all those parameters have defaults currently, in which case we'll need to do the same for these 2 as well.

@Dreamsorcerer Dreamsorcerer added this to the 4.0 milestone May 20, 2025
Copy link

codecov bot commented May 22, 2025

❌ 11 Tests Failed:

Tests completed Failed Passed Skipped
3834 11 3823 40
View the top 3 failed test(s) by shortest run time
tests.test_client_session::test_reraise_os_error[pyloop]
Stack Traces | 0.055s run time
create_session = <function create_session.<locals>.maker at 0x10515cf40>
create_mocked_conn = <function create_mocked_conn.<locals>._proto_factory at 0x10515ca40>

    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mtest_reraise_os_error#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        create_session: Callable[..., Awaitable[ClientSession]],#x1B[90m#x1B[39;49;00m
        create_mocked_conn: Callable[[], ResponseHandler],#x1B[90m#x1B[39;49;00m
    ) -> #x1B[94mNone#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
        err = #x1B[96mOSError#x1B[39;49;00m(#x1B[94m1#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mpermission error#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
        req = mock.Mock()#x1B[90m#x1B[39;49;00m
        req_factory = mock.Mock(return_value=req)#x1B[90m#x1B[39;49;00m
        req.send = mock.Mock(side_effect=err)#x1B[90m#x1B[39;49;00m
        session = #x1B[94mawait#x1B[39;49;00m create_session(request_class=req_factory)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mcreate_connection#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
            req: #x1B[96mobject#x1B[39;49;00m, traces: #x1B[96mobject#x1B[39;49;00m, timeout: #x1B[96mobject#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        ) -> ResponseHandler:#x1B[90m#x1B[39;49;00m
            #x1B[90m# return self.transport, self.protocol#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m create_mocked_conn()#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94mwith#x1B[39;49;00m mock.patch.object(session._connector, #x1B[33m"#x1B[39;49;00m#x1B[33m_create_connection#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, create_connection):#x1B[90m#x1B[39;49;00m
            #x1B[94mwith#x1B[39;49;00m mock.patch.object(#x1B[90m#x1B[39;49;00m
                session._connector, #x1B[33m"#x1B[39;49;00m#x1B[33m_release#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, autospec=#x1B[94mTrue#x1B[39;49;00m, spec_set=#x1B[94mTrue#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            ):#x1B[90m#x1B[39;49;00m
                #x1B[94mwith#x1B[39;49;00m pytest.raises(aiohttp.ClientOSError) #x1B[94mas#x1B[39;49;00m ctx:#x1B[90m#x1B[39;49;00m
>                   #x1B[94mawait#x1B[39;49;00m session.request(#x1B[33m"#x1B[39;49;00m#x1B[33mget#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mhttp://example.com#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m

create_connection = <function test_reraise_os_error.<locals>.create_connection at 0x10515c860>
create_mocked_conn = <function create_mocked_conn.<locals>._proto_factory at 0x10515ca40>
create_session = <function create_session.<locals>.maker at 0x10515cf40>
ctx        = <ExceptionInfo for raises contextmanager>
err        = PermissionError(1, 'permission error')
req        = <Mock id='4399778176'>
req_factory = <Mock id='4399780192'>
session    = <aiohttp.client.ClientSession object at 0x106452ac0>

#x1B[1m#x1B[31mtests/test_client_session.py#x1B[0m:478: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
#x1B[1m#x1B[31maiohttp/client.py#x1B[0m:688: in _request
    #x1B[0mresp = #x1B[94mawait#x1B[39;49;00m handler(req)#x1B[90m#x1B[39;49;00m
        _connect_and_send_request = <function ClientSession._request.<locals>._connect_and_send_request at 0x10515cea0>
        all_cookies = <SimpleCookie: >
        allow_redirects = True
        auth       = None
        auth_from_url = None
        auto_decompress = True
        chunked    = None
        compress   = False
        cookies    = None
        data       = None
        effective_middlewares = None
        expect100  = False
        handle     = None
        handler    = <function ClientSession._request.<locals>._connect_and_send_request at 0x10515cea0>
        headers    = <CIMultiDict()>
        history    = []
        json       = None
        max_field_size = 8190
        max_line_size = 8190
        max_redirects = 10
        method     = 'get'
        middlewares = None
        params     = {}
        proxy      = None
        proxy_     = None
        proxy_auth = None
        proxy_headers = None
        raise_for_status = None
        read_bufsize = 65536
        read_until_eof = True
        real_timeout = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        redirects  = 0
        req        = <Mock id='4399778176'>
        response_params = {'auto_decompress': True, 'max_field_size': 8190, 'max_line_size': 8190, 'read_bufsize': 65536, ...}
        retry_persistent_connection = False
        self       = <aiohttp.client.ClientSession object at 0x106452ac0>
        server_hostname = None
        skip_auto_headers = None
        skip_headers = None
        ssl        = True
        str_or_url = 'http://example.com'
        timeout    = <_SENTINEL.sentinel: 1>
        timer      = <aiohttp.helpers.TimerContext object at 0x1056d4300>
        tm         = <aiohttp.helpers.TimeoutHandle object at 0x10547eb00>
        trace_request_ctx = None
        traces     = []
        url        = URL('http://example.com')
        version    = HttpVersion(major=1, minor=1)
#x1B[1m#x1B[31maiohttp/client.py#x1B[0m:652: in _connect_and_send_request
    #x1B[0mconn = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._connector.connect(#x1B[90m#x1B[39;49;00m
        req        = <Mock id='4399778176'>
        self       = <aiohttp.client.ClientSession object at 0x106452ac0>
        traces     = []
#x1B[1m#x1B[31maiohttp/connector.py#x1B[0m:534: in connect
    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m ceil_timeout(timeout.connect, timeout.ceil_threshold):#x1B[90m#x1B[39;49;00m
        conn       = None
        key        = <Mock name='mock.connection_key' id='4399786912'>
        req        = <Mock id='4399778176'>
        self       = <aiohttp.connector.TCPConnector object at 0x105c06ad0>
        timeout    = <Mock name='mock._timeout' id='4399784224'>
        traces     = []
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

delay = <Mock name='mock._timeout.connect' id='4399790944'>
ceil_threshold = <Mock name='mock._timeout.ceil_threshold' id='4399782544'>

    #x1B[0m#x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mceil_timeout#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        delay: Optional[#x1B[96mfloat#x1B[39;49;00m], ceil_threshold: #x1B[96mfloat#x1B[39;49;00m = #x1B[94m5#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
    ) -> async_timeout.Timeout:#x1B[90m#x1B[39;49;00m
>       #x1B[94mif#x1B[39;49;00m delay #x1B[95mis#x1B[39;49;00m #x1B[94mNone#x1B[39;49;00m #x1B[95mor#x1B[39;49;00m delay <= #x1B[94m0#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
#x1B[1m#x1B[31mE       TypeError: '<=' not supported between instances of 'Mock' and 'int'#x1B[0m

ceil_threshold = <Mock name='mock._timeout.ceil_threshold' id='4399782544'>
delay      = <Mock name='mock._timeout.connect' id='4399790944'>

#x1B[1m#x1B[31maiohttp/helpers.py#x1B[0m:724: TypeError
tests.test_client_session::test_close_conn_on_error[pyloop]
Stack Traces | 0.056s run time
create_session = <function create_session.<locals>.maker at 0x10515c900>
create_mocked_conn = <function create_mocked_conn.<locals>._proto_factory at 0x10515d080>

    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mtest_close_conn_on_error#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        create_session: Callable[..., Awaitable[ClientSession]],#x1B[90m#x1B[39;49;00m
        create_mocked_conn: Callable[[], ResponseHandler],#x1B[90m#x1B[39;49;00m
    ) -> #x1B[94mNone#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
        #x1B[94mclass#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[04m#x1B[92mUnexpectedException#x1B[39;49;00m(#x1B[96mBaseException#x1B[39;49;00m):#x1B[90m#x1B[39;49;00m
            #x1B[94mpass#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        err = UnexpectedException(#x1B[33m"#x1B[39;49;00m#x1B[33mpermission error#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
        req = mock.Mock()#x1B[90m#x1B[39;49;00m
        req_factory = mock.Mock(return_value=req)#x1B[90m#x1B[39;49;00m
        req.send = mock.Mock(side_effect=err)#x1B[90m#x1B[39;49;00m
        session = #x1B[94mawait#x1B[39;49;00m create_session(request_class=req_factory)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        connections = []#x1B[90m#x1B[39;49;00m
        #x1B[94massert#x1B[39;49;00m session._connector #x1B[95mis#x1B[39;49;00m #x1B[95mnot#x1B[39;49;00m #x1B[94mNone#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        original_connect = session._connector.connect#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mconnect#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
            req: ClientRequest, traces: List[Trace], timeout: aiohttp.ClientTimeout#x1B[90m#x1B[39;49;00m
        ) -> Connection:#x1B[90m#x1B[39;49;00m
            conn = #x1B[94mawait#x1B[39;49;00m original_connect(req, traces, timeout)#x1B[90m#x1B[39;49;00m
            connections.append(conn)#x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m conn#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mcreate_connection#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
            req: #x1B[96mobject#x1B[39;49;00m, traces: #x1B[96mobject#x1B[39;49;00m, timeout: #x1B[96mobject#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        ) -> ResponseHandler:#x1B[90m#x1B[39;49;00m
            #x1B[90m# return self.transport, self.protocol#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            conn = create_mocked_conn()#x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m conn#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94mwith#x1B[39;49;00m mock.patch.object(session._connector, #x1B[33m"#x1B[39;49;00m#x1B[33mconnect#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, connect):#x1B[90m#x1B[39;49;00m
            #x1B[94mwith#x1B[39;49;00m mock.patch.object(#x1B[90m#x1B[39;49;00m
                session._connector, #x1B[33m"#x1B[39;49;00m#x1B[33m_create_connection#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, create_connection#x1B[90m#x1B[39;49;00m
            ):#x1B[90m#x1B[39;49;00m
                #x1B[94mwith#x1B[39;49;00m mock.patch.object(#x1B[90m#x1B[39;49;00m
                    session._connector, #x1B[33m"#x1B[39;49;00m#x1B[33m_release#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, autospec=#x1B[94mTrue#x1B[39;49;00m, spec_set=#x1B[94mTrue#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
                ):#x1B[90m#x1B[39;49;00m
                    #x1B[94mwith#x1B[39;49;00m pytest.raises(UnexpectedException):#x1B[90m#x1B[39;49;00m
>                       #x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m session.request(#x1B[33m"#x1B[39;49;00m#x1B[33mget#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mhttp://example.com#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m) #x1B[94mas#x1B[39;49;00m resp:#x1B[90m#x1B[39;49;00m

UnexpectedException = <class 'test_client_session.test_close_conn_on_error.<locals>.UnexpectedException'>
connect    = <function test_close_conn_on_error.<locals>.connect at 0x10515d1c0>
connections = []
create_connection = <function test_close_conn_on_error.<locals>.create_connection at 0x10515c720>
create_mocked_conn = <function create_mocked_conn.<locals>._proto_factory at 0x10515d080>
create_session = <function create_session.<locals>.maker at 0x10515c900>
err        = UnexpectedException('permission error')
original_connect = <bound method BaseConnector.connect of <aiohttp.connector.TCPConnector object at 0x105c06350>>
req        = <Mock id='4399787584'>
req_factory = <Mock id='4399781200'>
session    = <aiohttp.client.ClientSession object at 0x106453890>

#x1B[1m#x1B[31mtests/test_client_session.py#x1B[0m:523: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
#x1B[1m#x1B[31maiohttp/client.py#x1B[0m:1349: in __aenter__
    #x1B[0m#x1B[96mself#x1B[39;49;00m._resp: _RetType = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._coro#x1B[90m#x1B[39;49;00m
        self       = <aiohttp.client._BaseRequestContextManager object at 0x105566260>
#x1B[1m#x1B[31maiohttp/client.py#x1B[0m:688: in _request
    #x1B[0mresp = #x1B[94mawait#x1B[39;49;00m handler(req)#x1B[90m#x1B[39;49;00m
        _connect_and_send_request = <function ClientSession._request.<locals>._connect_and_send_request at 0x10515e340>
        all_cookies = <SimpleCookie: >
        allow_redirects = True
        auth       = None
        auth_from_url = None
        auto_decompress = True
        chunked    = None
        compress   = False
        cookies    = None
        data       = None
        effective_middlewares = None
        expect100  = False
        handle     = None
        handler    = <function ClientSession._request.<locals>._connect_and_send_request at 0x10515e340>
        headers    = <CIMultiDict()>
        history    = []
        json       = None
        max_field_size = 8190
        max_line_size = 8190
        max_redirects = 10
        method     = 'get'
        middlewares = None
        params     = {}
        proxy      = None
        proxy_     = None
        proxy_auth = None
        proxy_headers = None
        raise_for_status = None
        read_bufsize = 65536
        read_until_eof = True
        real_timeout = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        redirects  = 0
        req        = <Mock id='4399787584'>
        response_params = {'auto_decompress': True, 'max_field_size': 8190, 'max_line_size': 8190, 'read_bufsize': 65536, ...}
        retry_persistent_connection = False
        self       = <aiohttp.client.ClientSession object at 0x106453890>
        server_hostname = None
        skip_auto_headers = None
        skip_headers = None
        ssl        = True
        str_or_url = 'http://example.com'
        timeout    = <_SENTINEL.sentinel: 1>
        timer      = <aiohttp.helpers.TimerContext object at 0x104f89c00>
        tm         = <aiohttp.helpers.TimeoutHandle object at 0x104f88540>
        trace_request_ctx = None
        traces     = []
        url        = URL('http://example.com')
        version    = HttpVersion(major=1, minor=1)
#x1B[1m#x1B[31maiohttp/client.py#x1B[0m:652: in _connect_and_send_request
    #x1B[0mconn = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._connector.connect(#x1B[90m#x1B[39;49;00m
        req        = <Mock id='4399787584'>
        self       = <aiohttp.client.ClientSession object at 0x106453890>
        traces     = []
#x1B[1m#x1B[31mtests/test_client_session.py#x1B[0m:504: in connect
    #x1B[0mconn = #x1B[94mawait#x1B[39;49;00m original_connect(req, traces, timeout)#x1B[90m#x1B[39;49;00m
        connections = []
        original_connect = <bound method BaseConnector.connect of <aiohttp.connector.TCPConnector object at 0x105c06350>>
        req        = <Mock id='4399787584'>
        timeout    = <Mock name='mock._timeout' id='4399784896'>
        traces     = []
#x1B[1m#x1B[31maiohttp/connector.py#x1B[0m:534: in connect
    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m ceil_timeout(timeout.connect, timeout.ceil_threshold):#x1B[90m#x1B[39;49;00m
        conn       = None
        key        = <Mock name='mock.connection_key' id='4399777168'>
        req        = <Mock id='4399787584'>
        self       = <aiohttp.connector.TCPConnector object at 0x105c06350>
        timeout    = <Mock name='mock._timeout' id='4399784896'>
        traces     = []
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

delay = <Mock name='mock._timeout.connect' id='4399778848'>
ceil_threshold = <Mock name='mock._timeout.ceil_threshold' id='4399782880'>

    #x1B[0m#x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mceil_timeout#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        delay: Optional[#x1B[96mfloat#x1B[39;49;00m], ceil_threshold: #x1B[96mfloat#x1B[39;49;00m = #x1B[94m5#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
    ) -> async_timeout.Timeout:#x1B[90m#x1B[39;49;00m
>       #x1B[94mif#x1B[39;49;00m delay #x1B[95mis#x1B[39;49;00m #x1B[94mNone#x1B[39;49;00m #x1B[95mor#x1B[39;49;00m delay <= #x1B[94m0#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
#x1B[1m#x1B[31mE       TypeError: '<=' not supported between instances of 'Mock' and 'int'#x1B[0m

ceil_threshold = <Mock name='mock._timeout.ceil_threshold' id='4399782880'>
delay      = <Mock name='mock._timeout.connect' id='4399778848'>

#x1B[1m#x1B[31maiohttp/helpers.py#x1B[0m:724: TypeError
tests.test_client_session::test_ws_connect_unix_socket_allowed_protocols[pyloop-http]
Stack Traces | 0.096s run time
create_session = <function create_session.<locals>.maker at 0x10515f920>
create_mocked_conn = <function create_mocked_conn.<locals>._proto_factory at 0x10515e7a0>
protocol = 'http', ws_key = '/pmF6UoiAOTMcMPBUOinSevRNLY='
key_data = b'P\xc7R\xe3\x0e\x02@\x84~G\xa1\x8c\x1f\x895\x9b'

    #x1B[0m#x1B[37m@pytest#x1B[39;49;00m.mark.parametrize(#x1B[33m"#x1B[39;49;00m#x1B[33mprotocol#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, [#x1B[33m"#x1B[39;49;00m#x1B[33mhttp#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mhttps#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mws#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33mwss#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, #x1B[33m"#x1B[39;49;00m#x1B[33munix#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m])#x1B[90m#x1B[39;49;00m
    #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mtest_ws_connect_unix_socket_allowed_protocols#x1B[39;49;00m(  #x1B[90m# type: ignore[misc]#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        create_session: Callable[..., Awaitable[ClientSession]],#x1B[90m#x1B[39;49;00m
        create_mocked_conn: Callable[[], ResponseHandler],#x1B[90m#x1B[39;49;00m
        protocol: #x1B[96mstr#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
        ws_key: #x1B[96mstr#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
        key_data: #x1B[96mbytes#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
    ) -> #x1B[94mNone#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
        resp = mock.create_autospec(aiohttp.ClientResponse)#x1B[90m#x1B[39;49;00m
        resp.status = #x1B[94m101#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        resp.headers = {#x1B[90m#x1B[39;49;00m
            hdrs.UPGRADE: #x1B[33m"#x1B[39;49;00m#x1B[33mwebsocket#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            hdrs.CONNECTION: #x1B[33m"#x1B[39;49;00m#x1B[33mupgrade#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
            hdrs.SEC_WEBSOCKET_ACCEPT: ws_key,#x1B[90m#x1B[39;49;00m
        }#x1B[90m#x1B[39;49;00m
        resp.url = URL(#x1B[33mf#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m{#x1B[39;49;00mprotocol#x1B[33m}#x1B[39;49;00m#x1B[33m://example#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
        resp.cookies = SimpleCookie()#x1B[90m#x1B[39;49;00m
        resp.start = mock.AsyncMock()#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        req = mock.create_autospec(aiohttp.ClientRequest, spec_set=#x1B[94mTrue#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
        req_factory = mock.Mock(return_value=req)#x1B[90m#x1B[39;49;00m
        req.send = mock.AsyncMock(return_value=resp)#x1B[90m#x1B[39;49;00m
        #x1B[90m# UnixConnector allows all high level protocols by default and unix sockets#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        session = #x1B[94mawait#x1B[39;49;00m create_session(#x1B[90m#x1B[39;49;00m
            connector=UnixConnector(path=#x1B[33m"#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m), request_class=req_factory#x1B[90m#x1B[39;49;00m
        )#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        connections = []#x1B[90m#x1B[39;49;00m
        #x1B[94massert#x1B[39;49;00m session._connector #x1B[95mis#x1B[39;49;00m #x1B[95mnot#x1B[39;49;00m #x1B[94mNone#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        original_connect = session._connector.connect#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mconnect#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
            req: ClientRequest, traces: List[Trace], timeout: aiohttp.ClientTimeout#x1B[90m#x1B[39;49;00m
        ) -> Connection:#x1B[90m#x1B[39;49;00m
            conn = #x1B[94mawait#x1B[39;49;00m original_connect(req, traces, timeout)#x1B[90m#x1B[39;49;00m
            connections.append(conn)#x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m conn#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mcreate_connection#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
            req: #x1B[96mobject#x1B[39;49;00m, traces: #x1B[96mobject#x1B[39;49;00m, timeout: #x1B[96mobject#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        ) -> ResponseHandler:#x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m create_mocked_conn()#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        connector = session._connector#x1B[90m#x1B[39;49;00m
        #x1B[94mwith#x1B[39;49;00m (#x1B[90m#x1B[39;49;00m
            mock.patch.object(connector, #x1B[33m"#x1B[39;49;00m#x1B[33mconnect#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, connect),#x1B[90m#x1B[39;49;00m
            mock.patch.object(connector, #x1B[33m"#x1B[39;49;00m#x1B[33m_create_connection#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, create_connection),#x1B[90m#x1B[39;49;00m
            mock.patch.object(connector, #x1B[33m"#x1B[39;49;00m#x1B[33m_release#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m),#x1B[90m#x1B[39;49;00m
            mock.patch(#x1B[33m"#x1B[39;49;00m#x1B[33maiohttp.client.os#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m) #x1B[94mas#x1B[39;49;00m m_os,#x1B[90m#x1B[39;49;00m
        ):#x1B[90m#x1B[39;49;00m
            m_os.urandom.return_value = key_data#x1B[90m#x1B[39;49;00m
>           #x1B[94mawait#x1B[39;49;00m session.ws_connect(#x1B[33mf#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33m{#x1B[39;49;00mprotocol#x1B[33m}#x1B[39;49;00m#x1B[33m://example#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m

connect    = <function test_ws_connect_unix_socket_allowed_protocols.<locals>.connect at 0x10664a5c0>
connections = []
connector  = <aiohttp.connector.UnixConnector object at 0x1054bb620>
create_connection = <function test_ws_connect_unix_socket_allowed_protocols.<locals>.create_connection at 0x106648900>
create_mocked_conn = <function create_mocked_conn.<locals>._proto_factory at 0x10515e7a0>
create_session = <function create_session.<locals>.maker at 0x10515f920>
key_data   = b'P\xc7R\xe3\x0e\x02@\x84~G\xa1\x8c\x1f\x895\x9b'
m_os       = <MagicMock name='os' id='4401859616'>
original_connect = <bound method BaseConnector.connect of <aiohttp.connector.UnixConnector object at 0x1054bb620>>
protocol   = 'http'
req        = <MagicMock spec_set='ClientRequest' id='4402237792'>
req_factory = <Mock id='4401861296'>
resp       = <MagicMock spec='ClientResponse' id='4402499936'>
session    = <aiohttp.client.ClientSession object at 0x10606c590>
ws_key     = '/pmF6UoiAOTMcMPBUOinSevRNLY='

#x1B[1m#x1B[31mtests/test_client_session.py#x1B[0m:645: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
#x1B[1m#x1B[31maiohttp/client.py#x1B[0m:959: in _ws_connect
    #x1B[0mresp = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m.request(#x1B[90m#x1B[39;49;00m
        auth       = None
        autoclose  = True
        autoping   = True
        compress   = 0
        default_headers = {'Connection': 'Upgrade', 'Sec-WebSocket-Version': '13', 'Upgrade': 'websocket'}
        headers    = None
        heartbeat  = None
        key        = 'Sec-WebSocket-Version'
        max_msg_size = 4194304
        method     = 'GET'
        origin     = None
        params     = None
        protocols  = ()
        proxy      = None
        proxy_auth = None
        proxy_headers = None
        real_headers = <CIMultiDict('Upgrade': 'websocket', 'Connection': 'Upgrade', 'Sec-WebSocket-Version': '13', 'Sec-WebSocket-Key': 'UMdS4w4CQIR+R6GMH4k1mw==')>
        receive_timeout = None
        sec_key    = b'UMdS4w4CQIR+R6GMH4k1mw=='
        self       = <aiohttp.client.ClientSession object at 0x10606c590>
        server_hostname = None
        ssl        = True
        timeout    = <_SENTINEL.sentinel: 1>
        url        = 'http://example'
        value      = '13'
        ws_timeout = ClientWSTimeout(ws_receive=None, ws_close=10.0)
#x1B[1m#x1B[31maiohttp/client.py#x1B[0m:688: in _request
    #x1B[0mresp = #x1B[94mawait#x1B[39;49;00m handler(req)#x1B[90m#x1B[39;49;00m
        _connect_and_send_request = <function ClientSession._request.<locals>._connect_and_send_request at 0x106648cc0>
        all_cookies = <SimpleCookie: >
        allow_redirects = True
        auth       = None
        auth_from_url = None
        auto_decompress = True
        chunked    = None
        compress   = False
        cookies    = None
        data       = None
        effective_middlewares = None
        expect100  = False
        handle     = None
        handler    = <function ClientSession._request.<locals>._connect_and_send_request at 0x106648cc0>
        headers    = <CIMultiDict('Upgrade': 'websocket', 'Connection': 'Upgrade', 'Sec-WebSocket-Version': '13', 'Sec-WebSocket-Key': 'UMdS4w4CQIR+R6GMH4k1mw==')>
        history    = []
        json       = None
        max_field_size = 8190
        max_line_size = 8190
        max_redirects = 10
        method     = 'GET'
        middlewares = None
        params     = {}
        proxy      = None
        proxy_     = None
        proxy_auth = None
        proxy_headers = None
        raise_for_status = None
        read_bufsize = 65536
        read_until_eof = False
        real_timeout = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        redirects  = 0
        req        = <MagicMock spec_set='ClientRequest' id='4402237792'>
        response_params = {'auto_decompress': True, 'max_field_size': 8190, 'max_line_size': 8190, 'read_bufsize': 65536, ...}
        retry_persistent_connection = True
        self       = <aiohttp.client.ClientSession object at 0x10606c590>
        server_hostname = None
        skip_auto_headers = None
        skip_headers = None
        ssl        = True
        str_or_url = 'http://example'
        timeout    = <_SENTINEL.sentinel: 1>
        timer      = <aiohttp.helpers.TimerContext object at 0x105bdf300>
        tm         = <aiohttp.helpers.TimeoutHandle object at 0x105bdc2c0>
        trace_request_ctx = None
        traces     = []
        url        = URL('http://example')
        version    = HttpVersion(major=1, minor=1)
#x1B[1m#x1B[31maiohttp/client.py#x1B[0m:652: in _connect_and_send_request
    #x1B[0mconn = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._connector.connect(#x1B[90m#x1B[39;49;00m
        req        = <MagicMock spec_set='ClientRequest' id='4402237792'>
        self       = <aiohttp.client.ClientSession object at 0x10606c590>
        traces     = []
#x1B[1m#x1B[31mtests/test_client_session.py#x1B[0m:628: in connect
    #x1B[0mconn = #x1B[94mawait#x1B[39;49;00m original_connect(req, traces, timeout)#x1B[90m#x1B[39;49;00m
        connections = []
        original_connect = <bound method BaseConnector.connect of <aiohttp.connector.UnixConnector object at 0x1054bb620>>
        req        = <MagicMock spec_set='ClientRequest' id='4402237792'>
        timeout    = <NonCallableMagicMock name='mock._timeout' spec_set='ClientTimeout' id='4401857936'>
        traces     = []
#x1B[1m#x1B[31maiohttp/connector.py#x1B[0m:534: in connect
    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m ceil_timeout(timeout.connect, timeout.ceil_threshold):#x1B[90m#x1B[39;49;00m
        conn       = None
        key        = <MagicMock name='mock.connection_key' id='4401857600'>
        req        = <MagicMock spec_set='ClientRequest' id='4402237792'>
        self       = <aiohttp.connector.UnixConnector object at 0x1054bb620>
        timeout    = <NonCallableMagicMock name='mock._timeout' spec_set='ClientTimeout' id='4401857936'>
        traces     = []
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

delay = <NonCallableMagicMock name='mock._timeout.connect' id='4397484080'>
ceil_threshold = <NonCallableMagicMock name='mock._timeout.ceil_threshold' spec_set='int' id='4402413648'>

    #x1B[0m#x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mceil_timeout#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        delay: Optional[#x1B[96mfloat#x1B[39;49;00m], ceil_threshold: #x1B[96mfloat#x1B[39;49;00m = #x1B[94m5#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
    ) -> async_timeout.Timeout:#x1B[90m#x1B[39;49;00m
>       #x1B[94mif#x1B[39;49;00m delay #x1B[95mis#x1B[39;49;00m #x1B[94mNone#x1B[39;49;00m #x1B[95mor#x1B[39;49;00m delay <= #x1B[94m0#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
#x1B[1m#x1B[31mE       TypeError: '<=' not supported between instances of 'NonCallableMagicMock' and 'int'#x1B[0m

ceil_threshold = <NonCallableMagicMock name='mock._timeout.ceil_threshold' spec_set='int' id='4402413648'>
delay      = <NonCallableMagicMock name='mock._timeout.connect' id='4397484080'>

#x1B[1m#x1B[31maiohttp/helpers.py#x1B[0m:724: TypeError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@Dreamsorcerer
Copy link
Member Author

Otherwise, I guess that's why all those parameters have defaults currently, in which case we'll need to do the same for these 2 as well.

Feels to me like there should be a separate ClientProxyRequest or something. I think if we separated them, it'd remove a bunch of asserts and make static typing a lot cleaner.

Copy link

codspeed-hq bot commented May 22, 2025

CodSpeed Performance Report

Merging #10890 will not alter performance

Comparing Dreamsorcerer-patch-4 (559d75a) with master (3c88f81)

Summary

✅ 59 untouched benchmarks

bdraco added a commit that referenced this pull request May 23, 2025
This will avoid one breaking change in 4.0 in when
we make the other change in #10890

closes #10905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip Skip backport bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant