18
18
from aws_wrapper .connection_provider import DriverConnectionProvider
19
19
from aws_wrapper .errors import AwsWrapperError
20
20
from aws_wrapper .host_list_provider import AuroraHostListProvider
21
- from aws_wrapper .pep249 import Connection , Cursor , Error
21
+ from aws_wrapper .pep249 import Connection , Cursor , Error , FailoverSuccessError
22
22
from aws_wrapper .plugin import CanReleaseResources
23
23
from aws_wrapper .plugin_service import (PluginManager , PluginService ,
24
24
PluginServiceImpl ,
@@ -92,7 +92,8 @@ def close(self) -> None:
92
92
lambda : self .target_connection .close ())
93
93
94
94
def cursor (self , ** kwargs : Union [None , int , str ]) -> "AwsWrapperCursor" :
95
- return AwsWrapperCursor (self , self ._plugin_manager )
95
+ _cursor = self .target_connection .cursor (** kwargs )
96
+ return AwsWrapperCursor (self , self ._plugin_manager , _cursor )
96
97
97
98
def commit (self ) -> None :
98
99
self ._plugin_manager .execute (self .target_connection , "Connection.commit" ,
@@ -141,9 +142,10 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
141
142
class AwsWrapperCursor (Cursor ):
142
143
__module__ = "aws_wrapper"
143
144
144
- def __init__ (self , conn : AwsWrapperConnection , plugin_manager : PluginManager ):
145
+ def __init__ (self , conn : AwsWrapperConnection , plugin_manager : PluginManager , target_cursor : Cursor ):
145
146
self ._conn : AwsWrapperConnection = conn
146
147
self ._plugin_manager : PluginManager = plugin_manager
148
+ self ._target_cursor : Cursor = target_cursor
147
149
148
150
# It's not part of PEP249
149
151
@property
@@ -152,7 +154,7 @@ def connection(self) -> AwsWrapperConnection:
152
154
153
155
@property
154
156
def target_cursor (self ) -> Cursor :
155
- return self .connection . target_connection . cursor ()
157
+ return self ._target_cursor
156
158
157
159
@property
158
160
def description (self ):
@@ -179,8 +181,12 @@ def execute(
179
181
query : str ,
180
182
** kwargs : Union [None , int , str ]
181
183
) -> "AwsWrapperCursor" :
182
- return self ._plugin_manager .execute (self .target_cursor , "Cursor.execute" ,
183
- lambda : self .target_cursor .execute (query , ** kwargs ), query , kwargs )
184
+ try :
185
+ return self ._plugin_manager .execute (self .target_cursor , "Cursor.execute" ,
186
+ lambda : self .target_cursor .execute (query , ** kwargs ), query , kwargs )
187
+ except FailoverSuccessError as e :
188
+ self ._target_cursor = self .connection .target_connection .cursor ()
189
+ raise e
184
190
185
191
def executemany (
186
192
self ,
0 commit comments