Repository navigation
fix: open audit log and tee/once files as UTF-8 - #2429
Merged
Merged
Conversation
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'.
Contributor
|
Thank you! |
3 tasks done
3 tasks done
Contributor
|
Released in https://github.com/dbcli/mycli/releases/tag/v2.31.0 ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The audit log (
audit_loginmyclirc), the\Ttee file and the\o/\oncefile (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 raisesUnicodeEncodeError, so the entry is lost. The--logfileoption (click.File(mode='a', encoding='utf-8')) and the config/history files already use UTF-8; these fouropen()calls were the remaining ones without it.Fix: pass
encoding='utf-8'inclient.py(audit log) and inio_commands.py(set_tee,_set_once_file,flush_pipe_once_if_written).Tests:
test_init_opens_audit_log_from_confignow asserts the audit log is UTF-8, and the newtest_tee_and_once_files_are_opened_as_utf8writes日本語 🙂through\Tand checks the\ofile encoding. Both fail onmainand pass with the fix when run withLC_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
changelog.mdfile.mycli/AUTHORS.txtfile (or it's already there).ruff checkandruff format --checkpass on the touched files;mypywas not run (the change only adds anencodingkeyword).