From 5ad5bd3cbad80569d27868caa15ca267ca47fd57 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 16 Jun 2026 16:04:08 +0000 Subject: [PATCH 1/3] Fix tethys db configure encoding error on Windows by using template0 (issue #1250) --- tests/unit_tests/test_tethys_cli/test_db_commands.py | 2 ++ tethys_cli/db_commands.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/unit_tests/test_tethys_cli/test_db_commands.py b/tests/unit_tests/test_tethys_cli/test_db_commands.py index 61ca543e5..3c9820304 100644 --- a/tests/unit_tests/test_tethys_cli/test_db_commands.py +++ b/tests/unit_tests/test_tethys_cli/test_db_commands.py @@ -296,6 +296,8 @@ def test_db_command_create_db_user(self): "postgres", "-E", "utf-8", + "--template", + "template0", "-p", self.options["port"], "-O", diff --git a/tethys_cli/db_commands.py b/tethys_cli/db_commands.py index ae1fdd0cf..32f6b8852 100644 --- a/tethys_cli/db_commands.py +++ b/tethys_cli/db_commands.py @@ -316,6 +316,8 @@ def create_db_user( "postgres", "-E", "utf-8", + "--template", + "template0", "-p", f"{port}", "-O", From ef29047c1ea5000d4ad3d03147c6e5e1b3a76afe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Jul 2026 21:26:31 +0000 Subject: [PATCH 2/3] Initialize local PostgreSQL clusters as UTF-8 on Windows --- .../test_tethys_cli/test_db_commands.py | 25 +++++++++++++++++-- tethys_cli/db_commands.py | 4 +-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/test_tethys_cli/test_db_commands.py b/tests/unit_tests/test_tethys_cli/test_db_commands.py index 3c9820304..a077a2941 100644 --- a/tests/unit_tests/test_tethys_cli/test_db_commands.py +++ b/tests/unit_tests/test_tethys_cli/test_db_commands.py @@ -198,6 +198,29 @@ def test_db_command_init(self): **kwargs, ) + @mock.patch("tethys_cli.db_commands.sys.platform", "win32") + def test_db_command_init_windows(self): + mock_args = mock.MagicMock() + mock_args.command = "init" + db_command(mock_args) + kwargs = self._get_kwargs(remove=["db_dir"]) + self.mock_run_process.assert_called_with( + [ + "initdb", + "-U", + "postgres", + "-D", + "foo/data", + "--encoding", + "UTF8", + "--locale", + "C", + ], + 'Initializing Postgresql database server in "foo/data"...', + "Could not initialize the Postgresql database.", + **kwargs, + ) + @mock.patch("tethys_cli.db_commands.write_error") @mock.patch("tethys_cli.db_commands.create_db_user") def test_db_command_create_error_code_without_exit( @@ -296,8 +319,6 @@ def test_db_command_create_db_user(self): "postgres", "-E", "utf-8", - "--template", - "template0", "-p", self.options["port"], "-O", diff --git a/tethys_cli/db_commands.py b/tethys_cli/db_commands.py index 32f6b8852..bf86f041c 100644 --- a/tethys_cli/db_commands.py +++ b/tethys_cli/db_commands.py @@ -156,6 +156,8 @@ def init_db_server(db_dir=None, **kwargs): msg = f'Initializing Postgresql database server in "{db_dir}/data"...' err_msg = "Could not initialize the Postgresql database." args = ["initdb", "-U", "postgres", "-D", f"{db_dir}/data"] + if sys.platform == "win32": + args.extend(["--encoding", "UTF8", "--locale", "C"]) return _run_process(args, msg, err_msg, **kwargs) @@ -316,8 +318,6 @@ def create_db_user( "postgres", "-E", "utf-8", - "--template", - "template0", "-p", f"{port}", "-O", From 13744b59f4668d4373e8cb847546e502cb47eb39 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Jul 2026 20:07:23 +0000 Subject: [PATCH 3/3] Add --template template0 to createdb and update test coverage --- tests/unit_tests/test_tethys_cli/test_db_commands.py | 2 ++ tethys_cli/db_commands.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/unit_tests/test_tethys_cli/test_db_commands.py b/tests/unit_tests/test_tethys_cli/test_db_commands.py index a077a2941..d95dfaf3c 100644 --- a/tests/unit_tests/test_tethys_cli/test_db_commands.py +++ b/tests/unit_tests/test_tethys_cli/test_db_commands.py @@ -319,6 +319,8 @@ def test_db_command_create_db_user(self): "postgres", "-E", "utf-8", + "--template", + "template0", "-p", self.options["port"], "-O", diff --git a/tethys_cli/db_commands.py b/tethys_cli/db_commands.py index bf86f041c..2600935f3 100644 --- a/tethys_cli/db_commands.py +++ b/tethys_cli/db_commands.py @@ -318,6 +318,8 @@ def create_db_user( "postgres", "-E", "utf-8", + "--template", + "template0", "-p", f"{port}", "-O",