Skip to content

Commit f4cc8d5

Browse files
committed
BUG23622215: Fix missing arguments in transaction methods
The following error is thrown on using any of the transaction methods: TypeError: execute_nonquery() takes at least 3 arguments (2 given) Adding the required arguments in the call to `execute_nonquery` from each of the transaction methods. Test cases were added for regression.
1 parent 97aa93e commit f4cc8d5

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

lib/mysqlx/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,19 @@ def create_schema(self, name):
182182
def start_transaction(self):
183183
"""Starts a transaction context on the server.
184184
"""
185-
self._connection.execute_nonquery("START TRANSACTION")
185+
self._connection.execute_nonquery("sql", "START TRANSACTION", True)
186186

187187
def commit(self):
188188
"""Commits all the operations executed after a call to
189189
startTransaction().
190190
"""
191-
self._connection.execute_nonquery("COMMIT")
191+
self._connection.execute_nonquery("sql", "COMMIT", True)
192192

193193
def rollback(self):
194194
"""Discards all the operations executed after a call to
195195
startTransaction().
196196
"""
197-
self._connection.execute_nonquery("ROLLBACK")
197+
self._connection.execute_nonquery("sql", "ROLLBACK", True)
198198

199199

200200
class XSession(BaseSession):

tests/test_mysqlx_connection.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,45 @@ def test_create_schema(self):
106106
def test_sql(self):
107107
statement = self.session.sql("SELECT VERSION()")
108108
self.assertTrue(isinstance(statement, mysqlx.statement.Statement))
109+
110+
def test_rollback(self):
111+
table_name = "t2"
112+
schema = self.session.get_schema(self.schema_name)
113+
114+
if not schema.exists_in_database():
115+
self.session.create_schema(self.schema_name)
116+
117+
stmt = "CREATE TABLE {0}.{1}(_id INT)"
118+
self.session.sql(stmt.format(self.schema_name, table_name)).execute()
119+
table = schema.get_table(table_name)
120+
121+
self.session.start_transaction()
122+
123+
table.insert("_id").values(1).execute()
124+
self.assertEqual(table.count(), 1)
125+
126+
self.session.rollback()
127+
self.assertEqual(table.count(), 0)
128+
129+
schema.drop_table(table_name)
130+
131+
def test_commit(self):
132+
table_name = "t2"
133+
schema = self.session.get_schema(self.schema_name)
134+
135+
if not schema.exists_in_database():
136+
self.session.create_schema(self.schema_name)
137+
138+
stmt = "CREATE TABLE {0}.{1}(_id INT)"
139+
self.session.sql(stmt.format(self.schema_name, table_name)).execute()
140+
table = schema.get_table(table_name)
141+
142+
self.session.start_transaction()
143+
144+
table.insert("_id").values(1).execute()
145+
self.assertEqual(table.count(), 1)
146+
147+
self.session.commit()
148+
self.assertEqual(table.count(), 1)
149+
150+
schema.drop_table(table_name)

0 commit comments

Comments
 (0)