Skip to content

fix: Non-ASCII characters (e.g. accented letters) in a data contract … - #1650

Merged
jschoedl merged 5 commits into
datacontract:mainfrom
ymurong:feat/excel-export-encoding
Sep 24, 2026
Merged

jschoedl merged 5 commits into
datacontract:mainfrom
ymurong:feat/excel-export-encoding

Conversation

@ymurong

@ymurong ymurong commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Non-ASCII characters (e.g. accented letters) in a data contract file were garbled on Windows

  • Tests pass (uv run pytest)
  • Code formatted (uv run ruff check --fix && uv run ruff format)
  • Docs updated (if relevant)
  • CHANGELOG.md entry added

Comment thread datacontract/lint/schema.py Dismissed
The non_utf8_default_encoding fixture now mirrors open()'s signature (a positional buffering argument no longer lands in encoding) and also patches io.open, so Path.open and importlib.resources reads default to cp1252 too. New tests check that fetch_schema decodes both the bundled and a local schema file as UTF-8.
…s UTF-8

Importers (avro, bigquery, dbml, dcs, iceberg, jsonschema, protobuf, sql, unity), datacontract init, the config file and the saved API response of datacontract test used the platform default encoding. On Windows, non-ASCII characters in these files were garbled, or a protobuf source crashed with UnicodeDecodeError.

@jschoedl jschoedl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I pushed two commits on top:

  • small fix to Tests: the non_utf8_default_encoding fixture now takes its arguments in the same order as open(), so a call like open(p, "r", -1) no longer puts -1 into encoding. It also patches io.open, which lets it reach Path.open/importlib.resources reads. That way the fetch_schema change is covered too; the new tests are in tests/test_lint_schema.py.
  • More files: I used the opportunity to fix the same problem in the other places that read or write files with the default encoding

Comment thread tests/test_export_excel.py Outdated
@jschoedl jschoedl linked an issue Sep 23, 2026 that may be closed by this pull request
ymurong and others added 2 commits September 23, 2026 19:21
The accented-characters test in test_export_excel.py is redundant — the core
encoding fix is already well-covered by test_lint_files.py, which exercises
the same code path under a cp1252 default encoding via the non_utf8_default_encoding
fixture. There is no Excel-specific behavior to test here.
@jschoedl
jschoedl merged commit 3e7ff42 into datacontract:main Sep 24, 2026
2 checks passed
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.

Excel export corrupts French accented characters

3 participants