Skip to content

fix: open audit log and tee/once files as UTF-8 - #2429

Merged
rolandwalker merged 1 commit into
dbcli:mainfrom
pcbeingused333:fix/file-encoding-utf8
Nov 13, 2026
Merged

rolandwalker merged 1 commit into
dbcli:mainfrom
pcbeingused333:fix/file-encoding-utf8

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Description

The audit log (audit_log in myclirc), the \T tee file and the \o/\once file (plus the pipe-once stdout file) were opened with the locale's default encoding. Under a non-UTF-8 locale (Windows cp1252, LANG=C) writing CJK or emoji output raises UnicodeEncodeError, so the entry is lost. The --logfile option (click.File(mode='a', encoding='utf-8')) and the config/history files already use UTF-8; these four open() calls were the remaining ones without it.

Fix: pass encoding='utf-8' in client.py (audit log) and in io_commands.py (set_tee, _set_once_file, flush_pipe_once_if_written).

Tests: test_init_opens_audit_log_from_config now asserts the audit log is UTF-8, and the new test_tee_and_once_files_are_opened_as_utf8 writes 日本語 🙂 through \T and checks the \o file encoding. Both fail on main and pass with the fix when run with LC_ALL=C PYTHONUTF8=0 PYTHONCOERCECLOCALE=0 uv run pytest mycli_test/pytests/test_client.py mycli_test/pytests/test_special_io_commands.py.

Disclosure: this change was prepared with the help of an AI coding assistant (Claude); the submitter is responsible for it.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

ruff check and ruff format --check pass on the touched files; mypy was not run (the change only adds an encoding keyword).

These files were opened with the locale default encoding, so writing non-ASCII query output failed under non-UTF-8 locales (Windows cp1252, LANG=C). The config and history files already pass encoding='utf-8'.
@rolandwalker
rolandwalker merged commit 7b66de2 into dbcli:main Nov 13, 2026
13 checks passed
@rolandwalker

Copy link
Copy Markdown
Contributor

Thank you!

@rolandwalker

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants