Skip to content

fix: add encoding='utf-8' to open() calls to prevent UnicodeDecodeError on non-UTF-8 systems#4287

Open
nandithasalim wants to merge 1 commit into
traceloop:mainfrom
nandithasalim:fix/add-utf8-encoding
Open

fix: add encoding='utf-8' to open() calls to prevent UnicodeDecodeError on non-UTF-8 systems#4287
nandithasalim wants to merge 1 commit into
traceloop:mainfrom
nandithasalim:fix/add-utf8-encoding

Conversation

@nandithasalim

@nandithasalim nandithasalim commented Jun 17, 2026

Copy link
Copy Markdown

Fixes #4286

On Windows systems with non-UTF-8 locales (e.g. GBK), open() calls
without explicit encoding crash with UnicodeDecodeError.

Added encoding='utf-8' to text-mode open() calls in:

  • packages/opentelemetry-instrumentation-qdrant/init.py (lines 26, 30)
  • scripts/codegen/generate_evaluator_models.py (line 27)

Summary by CodeRabbit

  • Bug Fixes
    • Improved character encoding handling by explicitly specifying UTF-8 when reading configuration and API specification files, ensuring consistent behavior across all operating systems and platform settings.

@CLAassistant

CLAassistant commented Jun 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2069a2a0-0868-40cb-b986-2d3ab721843f

📥 Commits

Reviewing files that changed from the base of the PR and between fc33f1c and fd59b57.

📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/__init__.py
  • scripts/codegen/generate_evaluator_models.py

📝 Walkthrough

Walkthrough

Two open() calls in the Qdrant instrumentation package and one in the evaluator models codegen script are updated to pass encoding="utf-8" explicitly, replacing reliance on the platform's default encoding.

Changes

UTF-8 Encoding Fix

Layer / File(s) Summary
Explicit UTF-8 encoding for JSON and Swagger file reads
packages/opentelemetry-instrumentation-qdrant/opentelemetry/instrumentation/qdrant/__init__.py, scripts/codegen/generate_evaluator_models.py
Both the synchronous and async Qdrant client methods JSON file reads and the Swagger file read in the codegen script now pass encoding="utf-8" to open().

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit once read a JSON with fright,
On Windows the encoding was never quite right.
But now UTF-8 is passed with care,
GBK and CP1252 beware!
The bytes flow in clean, day and night. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding encoding='utf-8' to open() calls to prevent UnicodeDecodeError on non-UTF-8 systems.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #4286 by adding encoding='utf-8' to open() calls in both specified files at the exact locations identified.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of adding encoding='utf-8' parameters to open() calls in the two specified files. No out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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