Skip to content

Commit 1fd334d

Browse files
authored
Refresh cursor only after failover (#65)
### Description Fix cursor issue breaking integration tests. ### By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 89b92e4 commit 1fd334d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

aws_wrapper/wrapper.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from aws_wrapper.connection_provider import DriverConnectionProvider
1919
from aws_wrapper.errors import AwsWrapperError
2020
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
2222
from aws_wrapper.plugin import CanReleaseResources
2323
from aws_wrapper.plugin_service import (PluginManager, PluginService,
2424
PluginServiceImpl,
@@ -92,7 +92,8 @@ def close(self) -> None:
9292
lambda: self.target_connection.close())
9393

9494
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)
9697

9798
def commit(self) -> None:
9899
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:
141142
class AwsWrapperCursor(Cursor):
142143
__module__ = "aws_wrapper"
143144

144-
def __init__(self, conn: AwsWrapperConnection, plugin_manager: PluginManager):
145+
def __init__(self, conn: AwsWrapperConnection, plugin_manager: PluginManager, target_cursor: Cursor):
145146
self._conn: AwsWrapperConnection = conn
146147
self._plugin_manager: PluginManager = plugin_manager
148+
self._target_cursor: Cursor = target_cursor
147149

148150
# It's not part of PEP249
149151
@property
@@ -152,7 +154,7 @@ def connection(self) -> AwsWrapperConnection:
152154

153155
@property
154156
def target_cursor(self) -> Cursor:
155-
return self.connection.target_connection.cursor()
157+
return self._target_cursor
156158

157159
@property
158160
def description(self):
@@ -179,8 +181,12 @@ def execute(
179181
query: str,
180182
**kwargs: Union[None, int, str]
181183
) -> "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
184190

185191
def executemany(
186192
self,

0 commit comments

Comments
 (0)