Skip to content

fix: add explicit encoding='utf-8' to open() calls for Windows compat#4333

Open
truecallerabreham wants to merge 1 commit into
traceloop:mainfrom
truecallerabreham:main
Open

fix: add explicit encoding='utf-8' to open() calls for Windows compat#4333
truecallerabreham wants to merge 1 commit into
traceloop:mainfrom
truecallerabreham:main

Conversation

@truecallerabreham

@truecallerabreham truecallerabreham commented Jun 28, 2026

Copy link
Copy Markdown

Three open() calls in the codebase read text files without specifying an encoding. On Windows with non-UTF-8 locales (like GBK on Chinese Windows), this blows up with UnicodeDecodeError.

Added encoding=utf-8 to the two calls in the qdrant instrumentation __init__.py (loading the JSON method lists) and the one in generate_evaluator_models.py (reading the Swagger definition). That's it — three characters each, no behavioral change on systems that already default to UTF-8.

Existing tests cover the import path that triggers these reads, so passing tests confirms the fix works.

Closes #4286

Add encoding='utf-8' to three open() calls that read text files to
prevent UnicodeDecodeError crashes on Windows systems with non-UTF-8
system locales (e.g., GBK on Chinese Windows).

Fixes traceloop#4286
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Two files are updated to add encoding="utf-8" to open() calls: the Qdrant instrumentation module now opens both sync and async JSON method definition files with explicit UTF-8 encoding, and the codegen script opens the Swagger spec with explicit UTF-8 encoding.

UTF-8 encoding fix

Layer / File(s) Summary
Explicit UTF-8 encoding on open() calls
packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/__init__.py, scripts/codegen/generate_evaluator_models.py
Adds encoding="utf-8" to open() calls when reading JSON/Swagger files, preventing UnicodeDecodeError on systems with non-UTF-8 default locales.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 A rabbit once read a JSON file,
On Windows it crashed after a while!
"encoding='utf-8'!" I cried with glee,
Now every locale reads perfectly,
No more UnicodeError to revile! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding explicit UTF-8 encoding to open() calls for Windows compatibility.
Linked Issues check ✅ Passed The changes match #4286 by adding encoding='utf-8' to the listed text-mode open() calls in both affected files.
Out of Scope Changes check ✅ Passed The patch only touches the encoding of the targeted file reads and includes no unrelated code changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

fix: open() calls missing encoding='utf-8' may crash on non-UTF-8 systems

2 participants