Skip to content

Commit 2c294f7

Browse files
committed
fix(custom-pewee): Keep same signature of execute_sql function
1 parent 5c10214 commit 2c294f7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

agent/database.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ def default(self, obj):
645645
return str(obj)
646646

647647

648+
SENTINEL = object()
649+
650+
648651
class CustomPeeweeDB(peewee.MySQLDatabase):
649652
"""
650653
Override peewee.MySQLDatabase to modify `execute_sql` method
@@ -674,18 +677,19 @@ class CustomPeeweeDB(peewee.MySQLDatabase):
674677
def __init__(self, *args, **kwargs):
675678
super().__init__(*args, **kwargs)
676679

677-
def execute_sql(self, sql):
678-
if self.in_transaction():
679-
commit = False
680-
elif self.commit_select:
681-
commit = True
682-
else:
683-
commit = not sql[:6].lower().startswith("select")
680+
def execute_sql(self, sql, params=None, commit=SENTINEL):
681+
if commit is SENTINEL:
682+
if self.in_transaction():
683+
commit = False
684+
elif self.commit_select:
685+
commit = True
686+
else:
687+
commit = not sql[:6].lower().startswith("select")
684688

685689
with self.__exception_wrapper__:
686690
cursor = self.cursor(commit)
687691
try:
688-
cursor.execute(sql, None) # params passed as none
692+
cursor.execute(sql, params)
689693
except Exception:
690694
if self.autorollback and not self.in_transaction():
691695
self.rollback()

0 commit comments

Comments
 (0)