Skip to content

cz changelog --export-template raises UnicodeDecodeError on a non-ASCII template where the locale is not UTF-8 #2136

Backlog

Description

@stella-h-choi

Description

cz changelog --export-template reads and writes the template in the locale's encoding. Jinja reads the same template as UTF-8, so a template that renders can fail to export, for example one with Korean text where the locale is EUC-KR.

Steps to reproduce

On Linux with the ko_KR.EUC-KR locale generated, in an empty directory:

git init -q
printf '[tool.commitizen]\nname = "cz_conventional_commits"\nversion = "0.1.0"\ntemplate = "my.md.j2"\n' > pyproject.toml
printf '## \xeb\xb3\x80\xea\xb2\xbd \xe2\x9c\xa8\n' > my.md.j2
git commit -q --allow-empty -m "feat: start"
export LC_ALL=ko_KR.EUC-KR PYTHONUTF8=0 PYTHONIOENCODING=utf-8
cz changelog --dry-run
cz changelog --export-template out.md

Current behavior

cz changelog --dry-run renders the template. cz changelog --export-template out.md exits 1:

UnicodeDecodeError: 'euc_kr' codec can't decode byte 0x80 in position 5: illegal multibyte sequence

Desired behavior

out.md has the same bytes as my.md.j2, as it does under C.UTF-8.

Environment

Commitizen Version: 4.20.1 (master, 4c4b791)
Python Version: 3.14.4 (main, Aug 20 2026, 10:41:58) [GCC 15.2.0]
Operating System: Linux

I have not run cz itself on Windows. On Windows 11 with cp949, Path.read_text() of the same kind of text raises UnicodeDecodeError.

#1854 changed these two lines among others and was closed without a reproducing test. #2119 fixed cz commit --edit and cz init and did not touch them. I would like to send a PR with only these two lines and a test that fails without them, if you agree.

This was found and written with the help of Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions