File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212""" # noqa: E501
1313
1414
15+ import asyncio
1516import datetime
1617from dateutil .parser import parse
1718from enum import Enum
@@ -629,8 +630,22 @@ def update_params_for_auth(
629630 request_auth
630631 )
631632 else :
633+ auth_settings_callable = self .configuration .auth_settings
634+ # The auth_settings callable can be async, but this function is sync.
635+ # We need to run the coroutine to get the result. This is a workaround
636+ # for the generator producing mixed-style code.
637+ if asyncio .iscoroutinefunction (auth_settings_callable ):
638+ try :
639+ loop = asyncio .get_running_loop ()
640+ # This is a blocking call in an async context. It's not ideal, but it's
641+ # necessary here to contain the change to this file.
642+ auth_settings_dict = loop .run_until_complete (auth_settings_callable ())
643+ except RuntimeError : # No running event loop
644+ auth_settings_dict = asyncio .run (auth_settings_callable ())
645+ else :
646+ auth_settings_dict = auth_settings_callable ()
632647 for auth in auth_settings :
633- auth_setting = self . configuration . auth_settings () .get (auth )
648+ auth_setting = auth_settings_dict .get (auth )
634649 if auth_setting :
635650 self ._apply_auth_params (
636651 headers ,
You can’t perform that action at this time.
0 commit comments