Skip to content

Commit 83d8b4f

Browse files
committed
fix(physical-restore): Use overriden Pewwee class
In pewee implementation in execute_sql function if we pass params as null It will still set a blank tupple Underthehood mysql implementation will then trigger to assume all % as escape params, and as will eventually fail So, this override class, will pass the user provided params directly to mysql client object
1 parent e85e093 commit 83d8b4f

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

agent/database_physical_backup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import time
88
from random import randint
99

10-
import peewee
1110
import requests
1211

12+
from agent.database import CustomPeeweeDB
1313
from agent.database_server import DatabaseServer
1414
from agent.job import job, step
1515
from agent.utils import compute_file_hash, decode_mariadb_filename
@@ -31,7 +31,7 @@ def __init__(
3131
if not databases:
3232
raise ValueError("At least one database is required")
3333
# Instance variable for internal use
34-
self._db_instances: dict[str, peewee.MySQLDatabase] = {}
34+
self._db_instances: dict[str, CustomPeeweeDB] = {}
3535
self._db_tables_locked: dict[str, bool] = {db: False for db in databases}
3636

3737
# variables
@@ -296,7 +296,7 @@ def _unlock_tables(self, db_name):
296296
the tables will be unlocked automatically
297297
"""
298298

299-
def get_db(self, db_name: str) -> peewee.MySQLDatabase:
299+
def get_db(self, db_name: str) -> CustomPeeweeDB:
300300
instance = self._db_instances.get(db_name, None)
301301
if instance is not None:
302302
if not instance.is_connection_usable():
@@ -306,7 +306,7 @@ def get_db(self, db_name: str) -> peewee.MySQLDatabase:
306306
return instance
307307
if db_name not in self.databases:
308308
raise ValueError(f"Database {db_name} not found")
309-
self._db_instances[db_name] = peewee.MySQLDatabase(
309+
self._db_instances[db_name] = CustomPeeweeDB(
310310
db_name,
311311
user=self.db_user,
312312
password=self.db_password,

agent/database_physical_restore.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import shutil
77
import subprocess
88

9-
import peewee
10-
119
from agent.base import AgentException
10+
from agent.database import CustomPeeweeDB
1211
from agent.database_physical_backup import (
1312
DatabaseConnectionClosedWithDatabase,
1413
get_path_of_physical_backup_metadata,
@@ -34,8 +33,8 @@ def __init__(
3433
if tables_to_restore is None:
3534
tables_to_restore = []
3635

37-
self._target_db_instance: peewee.MySQLDatabase = None
38-
self._target_db_instance_for_myisam: peewee.MySQLDatabase = None
36+
self._target_db_instance: CustomPeeweeDB = None
37+
self._target_db_instance_for_myisam: CustomPeeweeDB = None
3938
self.target_db = target_db
4039
self.target_db_user = "root"
4140
self.target_db_password = target_db_root_password
@@ -317,13 +316,13 @@ def _perform_file_operations(self, engine: str):
317316
os.path.join(self.target_db_directory, file),
318317
)
319318

320-
def _get_target_db(self) -> peewee.MySQLDatabase:
319+
def _get_target_db(self) -> CustomPeeweeDB:
321320
if self._target_db_instance is not None:
322321
if not self._target_db_instance.is_connection_usable():
323322
raise DatabaseConnectionClosedWithDatabase()
324323
return self._target_db_instance
325324

326-
self._target_db_instance = peewee.MySQLDatabase(
325+
self._target_db_instance = CustomPeeweeDB(
327326
self.target_db,
328327
user=self.target_db_user,
329328
password=self.target_db_password,
@@ -335,13 +334,13 @@ def _get_target_db(self) -> peewee.MySQLDatabase:
335334
self._target_db_instance.execute_sql("SET SESSION wait_timeout = 14400;")
336335
return self._target_db_instance
337336

338-
def _get_target_db_for_myisam(self) -> peewee.MySQLDatabase:
337+
def _get_target_db_for_myisam(self) -> CustomPeeweeDB:
339338
if self._target_db_instance_for_myisam is not None:
340339
if not self._target_db_instance_for_myisam.is_connection_usable():
341340
raise DatabaseConnectionClosedWithDatabase()
342341
return self._target_db_instance_for_myisam
343342

344-
self._target_db_instance_for_myisam = peewee.MySQLDatabase(
343+
self._target_db_instance_for_myisam = CustomPeeweeDB(
345344
self.target_db,
346345
user=self.target_db_user,
347346
password=self.target_db_password,

0 commit comments

Comments
 (0)