Repository navigation
Read and write batch and checkpoint files as UTF-8 - #2434
Merged
Merged
Conversation
--batch files were read with the locale encoding, and the --checkpoint file was written with the locale encoding but read back as UTF-8. On Windows, non-ASCII batch files failed to load and --resume could not read the checkpoint. Read batch files as UTF-8 (standard input is unchanged) and write the checkpoint as UTF-8.
Contributor
|
Hi! Thanks! We love better Windows support! |
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
On Windows,
--batchand--checkpointdo not agree on the file encoding:--batchfiles are opened withclick.open_file(path), so they are read with the locale encoding (the ANSI code page on Windows, such as cp1252 or cp949).--checkpointfile is written withclick.open_file(path, mode='a')(locale encoding) inrun_query(), butreplay_checkpoint_file()reads it back withencoding='utf-8'.So on Windows, a UTF-8 batch file with any non-ASCII text fails to load or is read garbled, a statement with a character outside the code page cannot be written to the checkpoint, and
--resumecannot read back a checkpoint that holds a non-ASCII statement. On Linux and macOS the locale encoding is usually UTF-8, so the problem does not show there.Reproduction with the same
open()calls, Python 3.14 on Windows with the cp949 code page:(The batch file is
select 'Łukasz ✨';. The last line is a Korean statement written to the checkpoint with the locale encoding and read back as UTF-8, as--resumedoes.)This change:
--batchfiles as UTF-8. Standard input (--batch -) is left as before, so click still picks the console encoding.--checkpointfile as UTF-8, which matches howreplay_checkpoint_file()reads it.Tests:
test_main_batch_without_progress_bar_reads_utf8_batch_and_checkpointandtest_main_batch_with_progress_bar_reads_utf8_batchuse a UTF-8 batch file withŁukasz ✨.test_run_query_writes_checkpoint_as_utf8checks that the checkpoint is written as UTF-8.click.open_filefakes intest_main_modes_batch.pynow accept keyword arguments.On Windows 11 (cp949), Python 3.14,
uv run pytest mycli_test/pytests/test_main_modes_batch.py mycli_test/pytests/test_client_query.py: before the fix, the 3 new tests fail (3 failed, 74 passed, 6 skipped); with the fix, 77 passed, 6 skipped.Checklist
changelog.mdfile.mycli/AUTHORS.txtfile (or it's already there).ruff checkandruff format --checkpass. mypy on the changed files reports the same 4 errors before and after the change; they are Windows-only (pwdandos.getuidare missing there) and in other files.