Skip to content

Commit 94e50ba

Browse files
jackwotherspoonhessjcg
authored andcommitted
fix: error on connect_async() event loop mismatch
1 parent 2385f4f commit 94e50ba

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

google/cloud/sql/connector/connector.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ async def connect_async(
281281
KeyError: Unsupported database driver Must be one of pymysql, asyncpg,
282282
pg8000, and pytds.
283283
"""
284+
# check if event loop is running in current thread
285+
if self._loop != asyncio.get_running_loop():
286+
raise ConnectorLoopError(
287+
"Running event loop does not match 'connector._loop'. "
288+
"Connector.connect_async() must be called from the event loop "
289+
"the Connector was initialized with. If you need to connect "
290+
"across event loops/threads please use a new Connector object."
291+
)
292+
284293
if self._keys is None:
285294
self._keys = asyncio.create_task(generate_keys())
286295
if self._client is None:

0 commit comments

Comments
 (0)