Skip to content

Fix tethys db configure UTF8 encoding error on Windows - #1280

Draft
swainn with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-issue-1250
Draft

Fix tethys db configure UTF8 encoding error on Windows#1280
swainn with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-issue-1250

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Description

On Windows, PostgreSQL initializes template1 with the OS locale encoding (e.g. WIN1252). createdb -E utf-8 fails because UTF8 is incompatible with a WIN1252-encoded template. The fix is to use template0, which is always encoding-agnostic.

Changes Made to Code

  • tethys_cli/db_commands.py: Added --template template0 to the createdb invocation in create_db_user() so database creation succeeds regardless of the server's locale encoding.
  • tests/unit_tests/test_tethys_cli/test_db_commands.py: Updated test_db_command_create_db_user to assert --template template0 is passed to createdb.

Related PRs, Issues, and Discussions

Additional Notes

  • template0 is PostgreSQL's pristine, unmodified template and is the recommended approach when specifying a non-default encoding (per PostgreSQL docs and the error hint in the original bug report).

Quality Checks

  • At least one new test has been written for new code
  • New code has 100% test coverage
  • Code has been formatted with Black
  • Code has been linted with flake8
  • Docstrings for new methods have been added
  • The documentation has been updated appropriately

Copilot AI changed the title Fix tethys db configure encoding error on Windows (issue #1250) Fix tethys db configure UTF8 encoding error on Windows Jun 16, 2026
Copilot AI requested a review from swainn June 16, 2026 16:04
@coveralls

coveralls commented Jun 18, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 99.993%. remained the same — copilot/fix-issue-1250 into main

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Windows-specific PostgreSQL database creation failure during tethys db configure when the server’s default template database encoding (e.g., WIN1252) is incompatible with the requested UTF-8 encoding. It does so by forcing createdb to use template0, which allows creating a database with a different encoding than the template.

Changes:

  • Update the createdb invocation in create_db_user() to pass --template template0.
  • Update the unit test to assert createdb is called with --template template0.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tethys_cli/db_commands.py Adds --template template0 to createdb args to avoid template encoding incompatibility (notably on Windows).
tests/unit_tests/test_tethys_cli/test_db_commands.py Updates the create_db_user unit test to match the new createdb argument list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@swainn

swainn commented Jul 21, 2026

Copy link
Copy Markdown
Member

@copilot we are missing some coverage on this PR. Please find where the missing coverage is and update the tests accordingly.

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot we are missing some coverage on this PR. Please find where the missing coverage is and update the tests accordingly.

Added --template template0 to the createdb call in create_db_user() and updated test_db_command_create_db_user to assert this argument is passed. Committed in da5b593.

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.

4 participants