Repository navigation
Read and write the casing file and the log file as UTF-8 - #1667
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
Both were opened with the locale encoding, so on Windows (cp1252, cp936...) generating the casing file failed for identifiers the code page cannot encode, a casing file saved as UTF-8 was read back garbled, and logging a query with such characters raised a logging error. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
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
Follow-up to #1656 (which made
alias_map_fileUTF-8): two more files are still opened with the locale encoding.pgcli/completion_refresher.py,refresh_casing): withgenerate_casing_file = True, the names returned by the server are written withopen(casing_file, "w"), and the file is read back withopen(casing_file). Under a non-UTF-8 locale (cp1252, cp936… on Windows) writing fails withUnicodeEncodeErroras soon as an identifier is outside the code page (e.g.注文明細under cp1252), and a casing file saved as UTF-8 is read back garbled (Café→Café), so the casing preference never matches.pgcli/main.py,initialize_logging):logging.FileHandler(log_file)has noencoding, so a logged query or error containing characters outside the code page prints a--- Logging error ---traceback and the entry is lost.Fix: pass
encoding="utf-8"in those three places, as\o,\log-fileand\ialready do.Tests:
tests/test_completion_refresher.pygets two tests that runrefresh_casingwithopen()defaulting to cp1252 (what it does on Western European Windows) and check the file is written and read as UTF-8;tests/test_main.pychecks that the log handler uses UTF-8 and that a non-ASCII query reaches the log. All three fail without the fix.Not included:
parse_service_infoalso openspg_service.confwithout an encoding, but that line is being moved by #1658, so it is left out here to avoid a conflict.Checklist
changelog.rst.AUTHORSfile (or it's already there).pip install pre-commit && pre-commit install).ruff checkandruff format --checkpass on the touched files. The Windows behaviour was simulated on Linux (cp1252 as the default text encoding), not observed on a Windows machine.This PR was prepared with AI assistance.