@@ -64,40 +64,36 @@ def _run_code(self, code: str) -> None:
64
64
template = _jinja_env .get_template ("try_except_wrapper.py.jinja" )
65
65
error_file = self ._container .path ("/tmp/mysqlsh_error.json" )
66
66
67
- def render (connection_info : "relations.database_requires.ConnectionInformation" ):
68
- return template .render (
69
- username = connection_info .username ,
70
- password = connection_info .password ,
71
- host = connection_info .host ,
72
- port = connection_info .port ,
73
- code = code ,
74
- error_filepath = error_file .relative_to_container ,
75
- )
76
-
77
- # Redact password from log
78
- logged_script = render (self ._connection_info .redacted )
67
+ script = template .render (code = code , error_filepath = error_file .relative_to_container )
79
68
80
- script = render (self ._connection_info )
81
69
temporary_script_file = self ._container .path ("/tmp/mysqlsh_script.py" )
82
- error_file = self ._container .path ("/tmp/mysqlsh_error.json" )
83
70
temporary_script_file .write_text (script )
71
+
84
72
try :
85
- self ._container .run_mysql_shell ([
86
- "--no-wizard" ,
87
- "--python" ,
88
- "--file" ,
89
- str (temporary_script_file .relative_to_container ),
90
- ])
73
+ # https://bugs.mysql.com/bug.php?id=117429 details on why --no-wizard is omitted
74
+ self ._container .run_mysql_shell (
75
+ [
76
+ "--passwords-from-stdin" ,
77
+ "--uri" ,
78
+ f"{ self ._connection_info .username } @{ self ._connection_info .host } :{ self ._connection_info .port } " ,
79
+ "--python" ,
80
+ "--file" ,
81
+ str (temporary_script_file .relative_to_container ),
82
+ ],
83
+ input = self ._connection_info .password ,
84
+ )
91
85
except container .CalledProcessError as e :
92
86
logger .exception (
93
- f"Failed to run MySQL Shell script:\n { logged_script } \n \n stderr:\n { e .stderr } \n "
87
+ f"Failed to run MySQL Shell script:\n { script } \n \n stderr:\n { e .stderr } \n "
94
88
)
95
89
raise
96
90
finally :
97
91
temporary_script_file .unlink ()
92
+
98
93
with error_file .open ("r" ) as file :
99
94
exception = json .load (file )
100
95
error_file .unlink ()
96
+
101
97
try :
102
98
if exception :
103
99
raise ShellDBError (** exception )
@@ -107,7 +103,7 @@ def render(connection_info: "relations.database_requires.ConnectionInformation")
107
103
raise server_exceptions .ConnectionError_
108
104
else :
109
105
logger .exception (
110
- f"Failed to run MySQL Shell script:\n { logged_script } \n \n MySQL client error { e .code } \n MySQL Shell traceback:\n { e .traceback_message } \n "
106
+ f"Failed to run MySQL Shell script:\n { script } \n \n MySQL client error { e .code } \n MySQL Shell traceback:\n { e .traceback_message } \n "
111
107
)
112
108
raise
113
109
0 commit comments