Skip to content

Commit 436e951

Browse files
committed
continueAfterTimeout is not supported by batch
1 parent 27441ef commit 436e951

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

aurora_data_api/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,23 @@ def _format_parameter_set(self, parameters):
215215

216216
def _get_database_error(self, origin_error):
217217
error_msg = getattr(origin_error, "response", {}).get("Error", {}).get("Message", "")
218-
219-
# MySql error
220-
if error_msg.startswith("Database error code"):
221-
code, msg = (s.split(": ", 1)[1] for s in error_msg.split(". ", 1))
222-
return DatabaseError(MySQLErrorCodes(int(code)), msg)
223-
224-
# Postgresql error
225-
elif error_msg.startswith("ERROR"):
226-
msg, pos, code = postgresql_error_reg.match(error_msg).groups()
227-
return DatabaseError(PostgreSQLErrorCodes(code), msg, pos)
228-
229-
else:
230-
return DatabaseError(origin_error)
218+
try:
219+
if error_msg.startswith("Database error code"): # MySQL error
220+
code, msg = (s.split(": ", 1)[1] for s in error_msg.split(". ", 1))
221+
return DatabaseError(MySQLErrorCodes(int(code)), msg)
222+
elif error_msg.startswith("ERROR: "): # Postgresql error
223+
msg, pos, code = postgresql_error_reg.match(error_msg).groups()
224+
return DatabaseError(PostgreSQLErrorCodes(code), msg, pos)
225+
except Exception:
226+
pass
227+
return DatabaseError(origin_error)
231228

232229
def execute(self, operation, parameters=None):
233230
self._current_response, self._iterator, self._paging_state = None, None, None
234231
execute_statement_args = dict(self._prepare_execute_args(operation),
235232
includeResultMetadata=True)
233+
if self._continue_after_timeout is not None:
234+
execute_statement_args["continueAfterTimeout"] = self._continue_after_timeout
236235
if parameters:
237236
execute_statement_args["parameters"] = self._format_parameter_set(parameters)
238237
logger.debug("execute %s", reprlib.repr(operation.strip()))

aurora_data_api/postgresql_error_codes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,4 @@ class PostgreSQLErrorCodes(Enum):
251251
ER_ASSERT_FAILURE = 'P0004'
252252
ER_INTERNAL_ERROR = 'XX000'
253253
ER_DATA_CORRUPTED = 'XX001'
254-
ER_INDEX_CORRUPTED = 'XX002'
254+
ER_INDEX_CORRUPTED = 'XX002'

test/test.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def test_iterators(self):
118118
break
119119
self.assertIn(len(fm), [1001, 46])
120120

121+
@unittest.skip("This test now fails because the API was changed to terminate and delete the transaction when the "
122+
"data returned by the statement exceeds the limit, making automated recovery impossible.")
121123
def test_pagination_backoff(self):
122124
if self.using_mysql:
123125
return
@@ -161,24 +163,27 @@ def test_rowcount(self):
161163
def test_continue_after_timeout(self):
162164
if os.environ.get("TEST_CONTINUE_AFTER_TIMEOUT", "False") != "True":
163165
self.skipTest("TEST_CONTINUE_AFTER_TIMEOUT env var is not 'True'")
164-
166+
165167
if self.using_mysql:
166168
self.skipTest("Not implemented for MySQL")
167169

168170
try:
169171
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
170172
with self.assertRaisesRegex(conn._client.exceptions.ClientError, "StatementTimeoutException"):
171-
cur.execute("INSERT INTO aurora_data_api_test(name) SELECT 'continue_after_timeout' FROM (SELECT pg_sleep(50)) q")
173+
cur.execute(("INSERT INTO aurora_data_api_test(name) SELECT 'continue_after_timeout'"
174+
"FROM (SELECT pg_sleep(50)) q"))
172175
with self.assertRaisesRegex(aurora_data_api.DatabaseError, "current transaction is aborted"):
173176
cur.execute("SELECT COUNT(*) FROM aurora_data_api_test WHERE name = 'continue_after_timeout'")
174177

175178
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
176179
cur.execute("SELECT COUNT(*) FROM aurora_data_api_test WHERE name = 'continue_after_timeout'")
177180
self.assertEqual(cur.fetchone(), (0,))
178-
179-
with aurora_data_api.connect(database=self.db_name, continue_after_timeout=True) as conn, conn.cursor() as cur:
181+
182+
with aurora_data_api.connect(database=self.db_name,
183+
continue_after_timeout=True) as conn, conn.cursor() as cur:
180184
with self.assertRaisesRegex(conn._client.exceptions.ClientError, "StatementTimeoutException"):
181-
cur.execute("INSERT INTO aurora_data_api_test(name) SELECT 'continue_after_timeout' FROM (SELECT pg_sleep(50)) q")
185+
cur.execute(("INSERT INTO aurora_data_api_test(name) SELECT 'continue_after_timeout' "
186+
"FROM (SELECT pg_sleep(50)) q"))
182187
cur.execute("SELECT COUNT(*) FROM aurora_data_api_test WHERE name = 'continue_after_timeout'")
183188
self.assertEqual(cur.fetchone(), (1,))
184189
finally:

0 commit comments

Comments
 (0)