diff --git a/changelog.md b/changelog.md index c6f87f56..0b712a5a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,15 @@ Upcoming (TBD) ============== +Bug Fixes +-------- +* Update the prompt display logic to handle an edge case where a socket is used without + a host being parsed from any other method (#707). + + +1.42.0 (2025/12/20) +============== + Features -------- * Add support for the automatic displaying of warnings after a SQL statement is executed. diff --git a/mycli/main.py b/mycli/main.py index 6c227fcf..6f9965b5 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -1193,10 +1193,15 @@ def get_prompt(self, string: str) -> str: assert sqlexecute is not None assert sqlexecute.server_info is not None assert sqlexecute.server_info.species is not None - host = self.login_path if self.login_path and self.login_path_as_host else sqlexecute.host + if self.login_path and self.login_path_as_host: + prompt_host = self.login_path + elif sqlexecute.host is not None: + prompt_host = sqlexecute.host + else: + prompt_host = "localhost" now = datetime.now() string = string.replace("\\u", sqlexecute.user or "(none)") - string = string.replace("\\h", host or "(none)") + string = string.replace("\\h", prompt_host or "(none)") string = string.replace("\\d", sqlexecute.dbname or "(none)") string = string.replace("\\t", sqlexecute.server_info.species.name) string = string.replace("\\n", "\n") diff --git a/test/test_main.py b/test/test_main.py index 159c1ba7..34cbde66 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -11,7 +11,7 @@ from mycli.main import MyCli, cli, thanks_picker from mycli.packages.special.main import COMMANDS as SPECIAL_COMMANDS -from mycli.sqlexecute import ServerInfo +from mycli.sqlexecute import ServerInfo, SQLExecute from test.utils import HOST, PASSWORD, PORT, USER, dbtest, run test_dir = os.path.abspath(os.path.dirname(__file__)) @@ -37,6 +37,21 @@ ] +@dbtest +def test_prompt_no_host_only_socket(executor): + mycli = MyCli() + mycli.prompt_format = "\\t \\u@\\h:\\d> " + mycli.sqlexecute = SQLExecute + mycli.sqlexecute.server_info = ServerInfo.from_version_string("8.0.44-0ubuntu0.24.04.1") + mycli.sqlexecute.host = None + mycli.sqlexecute.socket = "/var/run/mysqld/mysqld.sock" + mycli.sqlexecute.user = "root" + mycli.sqlexecute.dbname = "mysql" + mycli.sqlexecute.port = "3306" + prompt = mycli.get_prompt(mycli.prompt_format) + assert prompt == "MySQL root@localhost:mysql> " + + @dbtest def test_enable_show_warnings(executor): mycli = MyCli()