From 69ddcc9fac2c67ea4d2fa8e16af14eeb8067a40e Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Fri, 16 Oct 2026 06:19:59 -0400 Subject: [PATCH] show the user in the prompt if a default was used instead of "(none)". This is a complete fix for the bug which was papered over for Docker in 6e0d16aa1. If a username was not given at the CLI with --user, and we fall back to a default user to make the connection, preserve the actual user for the connection in the SQLExecute instance. Later, the prompt correctly fills in the "\u" username escape from the user property of the SQLExecute instance. Storing the actual user instead of a None could be a help to other functionality beyond the prompt. --- changelog.md | 1 + mycli/packages/execution/sql_execute.py | 2 +- mycli_test/pytests/test_sql_execute.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index a5d663b0..0010dfc9 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ Upcoming (TBD) Bug Fixes -------- * Show the username in the Docker prompt. +* Show the username in the prompt if a default user was used. v2.29.6 (2026/10/15) diff --git a/mycli/packages/execution/sql_execute.py b/mycli/packages/execution/sql_execute.py index 5c5eebd3..8013753f 100644 --- a/mycli/packages/execution/sql_execute.py +++ b/mycli/packages/execution/sql_execute.py @@ -320,7 +320,7 @@ def connect( # Update them after the connection is made to ensure that it was a # successful connection. self.dbname = db - self.user = user + self.user = user or (conn.user.decode(conn.encoding) if isinstance(conn.user, bytes) else conn.user) self.password = password self.host = host self.port = port diff --git a/mycli_test/pytests/test_sql_execute.py b/mycli_test/pytests/test_sql_execute.py index 28a20ed1..61c28bff 100644 --- a/mycli_test/pytests/test_sql_execute.py +++ b/mycli_test/pytests/test_sql_execute.py @@ -841,6 +841,22 @@ def fake_reset_connection_id(self) -> None: assert executor.server_info.version == 80036 +@pytest.mark.parametrize('requested_user', [None, '']) +@pytest.mark.parametrize('resolved_user', ['andr\u00e9', b'andr\xe9']) +def test_connect_records_default_username(monkeypatch: pytest.MonkeyPatch, requested_user: str | None, resolved_user: str | bytes) -> None: + executor = make_executor_for_connect_tests() + executor.user = requested_user + executor.ssl = None + conn = Mock(user=resolved_user, encoding='latin1', server_version='5.7.0') + monkeypatch.setattr(sql_execute.pymysql, 'connect', Mock(return_value=conn)) + monkeypatch.setattr(SQLExecute, 'reset_connection_id', Mock()) + monkeypatch.setattr(SQLExecute, '_probe_doris_version', Mock(return_value=None)) + + executor.connect() + + assert executor.user == 'andr\u00e9' + + def test_connect_sets_expired_password_flag(monkeypatch) -> None: executor = make_executor_for_connect_tests() executor.ssl = None