Skip to content

Commit f270d59

Browse files
committed
BUG29833590: Calling execute() should fetch active results
An exception is raised, when executing statements consecutively without fetching the results. This patch fix this issue by fetching any active result.
1 parent 6ecddc5 commit f270d59

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

lib/mysqlx/connection.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ def _prepare_statement(self, msg_type, msg, statement):
576576
statement (Statement): A `Statement` based type object.
577577
"""
578578
try:
579+
self.fetch_active_result()
579580
self.protocol.send_prepare_prepare(msg_type, msg, statement)
580581
except NotSupportedError:
581582
self._prepared_stmt_supported = False
@@ -845,17 +846,17 @@ def close_session(self):
845846
if not self.is_open():
846847
return
847848

848-
# Deallocate all prepared statements
849-
if self._prepared_stmt_supported:
850-
for stmt_id in self._prepared_stmt_ids:
851-
self.protocol.send_prepare_deallocate(stmt_id)
852-
self._stmt_counter = 0
853-
854849
try:
855-
if self._active_result is not None:
856-
self._active_result.fetch_all()
857-
self.protocol.send_close()
858-
self.protocol.read_ok()
850+
# Fetch any active result
851+
self.fetch_active_result()
852+
# Deallocate all prepared statements
853+
if self._prepared_stmt_supported:
854+
for stmt_id in self._prepared_stmt_ids:
855+
self.protocol.send_prepare_deallocate(stmt_id)
856+
self._stmt_counter = 0
857+
# Send session close
858+
self.protocol.send_close()
859+
self.protocol.read_ok()
859860
except (InterfaceError, OperationalError) as err:
860861
_LOGGER.warning("Warning: An error occurred while attempting to "
861862
"close the connection: {}".format(err))

lib/mysqlx/protocol.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,17 +824,13 @@ def read_ok(self):
824824
825825
Raises:
826826
:class:`mysqlx.InterfaceError`: If unexpected message.
827-
:class:`mysqlx.ProgrammingError`: If unread result found.
828827
"""
829828
msg = self._reader.read_message()
830829
if msg.type == "Mysqlx.Error":
831830
raise InterfaceError("Mysqlx.Error: {}".format(msg["msg"]),
832831
errno=msg["code"])
833-
if msg.type == "Mysqlx.Resultset.Row":
834-
raise ProgrammingError("Unread result found")
835832
if msg.type != "Mysqlx.Ok":
836-
raise InterfaceError("Unexpected message encountered: {}"
837-
"".format(msg["msg"]))
833+
raise InterfaceError("Unexpected message encountered")
838834

839835
def send_connection_close(self):
840836
"""Send connection close."""

tests/test_mysqlx_crud.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,10 @@ def test_find(self):
13971397
# test unread result found
13981398
find = collection.find()
13991399
find.execute()
1400-
self.assertRaises(mysqlx.ProgrammingError, find.execute)
1400+
find.execute()
1401+
result = find.execute()
1402+
docs = result.fetch_all()
1403+
self.assertEqual(4, len(docs))
14011404

14021405
self.schema.drop_collection(collection_name)
14031406

0 commit comments

Comments
 (0)