@@ -72,12 +72,6 @@ def __init__(
7272 self ._global_connection = None # type: typing.Optional[Connection]
7373 self ._global_transaction = None # type: typing.Optional[Transaction]
7474
75- if self ._force_rollback :
76- self ._global_connection = Connection (self ._backend )
77- self ._global_transaction = self ._global_connection .transaction (
78- force_rollback = True
79- )
80-
8175 async def connect (self ) -> None :
8276 """
8377 Establish the connection pool.
@@ -91,7 +85,14 @@ async def connect(self) -> None:
9185 self .is_connected = True
9286
9387 if self ._force_rollback :
94- assert self ._global_transaction is not None
88+ assert self ._global_connection is None
89+ assert self ._global_transaction is None
90+
91+ self ._global_connection = Connection (self ._backend )
92+ self ._global_transaction = self ._global_connection .transaction (
93+ force_rollback = True
94+ )
95+
9596 await self ._global_transaction .__aenter__ ()
9697
9798 async def disconnect (self ) -> None :
@@ -101,9 +102,14 @@ async def disconnect(self) -> None:
101102 assert self .is_connected , "Already disconnected."
102103
103104 if self ._force_rollback :
105+ assert self ._global_connection is not None
104106 assert self ._global_transaction is not None
107+
105108 await self ._global_transaction .__aexit__ ()
106109
110+ self ._global_transaction = None
111+ self ._global_connection = None
112+
107113 await self ._backend .disconnect ()
108114 logger .info (
109115 "Disconnected from database %s" ,
0 commit comments