fix: add explicit encoding="utf-8" to text-mode open() calls#7095
Open
Ghraven wants to merge 1 commit into
Open
fix: add explicit encoding="utf-8" to text-mode open() calls#7095Ghraven wants to merge 1 commit into
Ghraven wants to merge 1 commit into
Conversation
Several text-mode open() calls in chromadb load or persist user-facing configuration and credential files without an explicit encoding= argument. Python falls back to locale.getpreferredencoding(), which is cp1252 on Windows and utf-8 on Linux/macOS — so a file written on one platform can become unreadable on another, and any non-ASCII content in user-supplied paths or values can fail to round- trip. Affected sites (7 total, 5 files): - chromadb/telemetry/product/__init__.py: 2 sites in TelemetryClient user-id read/write - chromadb/auth/__init__.py: 2 sites in credential and config file loaders - chromadb/cli/utils.py: 1 site in log-config loader - chromadb/utils/embedding_functions/schemas/registry.py: 1 site loading embedding-function JSON schemas - chromadb/utils/embedding_functions/schemas/schema_utils.py: 1 site loading embedding-function JSON schemas No behavior change on systems where the default encoding is already utf-8; eliminates locale-dependent breakage everywhere else. PEP 597 also recommends always specifying encoding= for text-mode opens.
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
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.
What
Several text-mode
open()calls inchromadbload or persist user-facing configuration and credential files without an explicitencoding=argument. Python falls back tolocale.getpreferredencoding(), which iscp1252on Windows andutf-8on Linux/macOS — so a file written on one platform can become unreadable on another, and any non-ASCII content in user-supplied paths or values can fail to round-trip.Why
encoding=for text-mode opens.EncodingWarningunderPYTHONWARNDEFAULTENCODING=1(Python 3.10+).Changes
Added
encoding="utf-8"to 7 text-modeopen()call sites across 5 files:chromadb/telemetry/product/__init__.py— 2 sites inTelemetryClientuser-id read/writechromadb/auth/__init__.py— 2 sites in credential and config file loaderschromadb/cli/utils.py— 1 site in log-config loaderchromadb/utils/embedding_functions/schemas/registry.py— 1 site loading embedding-function JSON schemaschromadb/utils/embedding_functions/schemas/schema_utils.py— 1 site loading embedding-function JSON schemasTotal: 5 files, +7/-7 lines.
Testing
Pure keyword-argument addition to existing
open()calls; no logic touched. Verified all 5 files parse cleanly withpython -m py_compile. The files were already being read/written as utf-8 in practice on Linux/macOS CI — this just makes it explicit and portable to Windows.