This repository was archived by the owner on Aug 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,9 @@ async def connect(self) -> None:
8181 """
8282 Establish the connection pool.
8383 """
84- assert not self .is_connected , "Already connected."
84+ if self .is_connected :
85+ logger .debug ("Already connected, skipping connection" )
86+ return None
8587
8688 await self ._backend .connect ()
8789 logger .info (
@@ -104,7 +106,9 @@ async def disconnect(self) -> None:
104106 """
105107 Close all connections in the connection pool.
106108 """
107- assert self .is_connected , "Already disconnected."
109+ if not self .is_connected :
110+ logger .debug ("Already disconnected, skipping disconnection" )
111+ return None
108112
109113 if self ._force_rollback :
110114 assert self ._global_connection is not None
Original file line number Diff line number Diff line change @@ -737,6 +737,14 @@ async def test_connect_and_disconnect(database_url):
737737 await database .disconnect ()
738738 assert not database .is_connected
739739
740+ # connect and disconnect idempotence
741+ await database .connect ()
742+ await database .connect ()
743+ assert database .is_connected
744+ await database .disconnect ()
745+ await database .disconnect ()
746+ assert not database .is_connected
747+
740748
741749@pytest .mark .parametrize ("database_url" , DATABASE_URLS )
742750@async_adapter
You can’t perform that action at this time.
0 commit comments