diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-07 10:11:41 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-04-07 10:12:19 +0200 |
| commit | b0d7753d07231fad780de61cd8bfddc5bbd1aa1c (patch) | |
| tree | 1543d04ec1dc6de49bcf60c3f3a01ba75378f470 | |
| parent | 0bc2bbf041df40a6ecb6262b2e5f3bb659dd8da8 (diff) | |
[4.2.x] Fixed #34470 -- Enforced UTF-8 encoding on PostgreSQL.
Regression in 6a2165816394ab4bb259f6171e82417e098e97a6.
Backport of 5b8a043bf51ab8bcf4a758d0b4646f30a84be183 from main
| -rw-r--r-- | django/db/backends/postgresql/base.py | 2 | ||||
| -rw-r--r-- | docs/releases/4.2.1.txt | 3 | ||||
| -rw-r--r-- | tests/backends/postgresql/tests.py | 12 |
3 files changed, 16 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index 5ed856448f..d92ad58710 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -208,7 +208,6 @@ class DatabaseWrapper(BaseDatabaseWrapper): self.ops.max_name_length(), ) ) - conn_params = {"client_encoding": "UTF8"} if settings_dict["NAME"]: conn_params = { "dbname": settings_dict["NAME"], @@ -220,6 +219,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): conn_params = {"dbname": "postgres", **settings_dict["OPTIONS"]} else: conn_params = {**settings_dict["OPTIONS"]} + conn_params["client_encoding"] = "UTF8" conn_params.pop("assume_role", None) conn_params.pop("isolation_level", None) diff --git a/docs/releases/4.2.1.txt b/docs/releases/4.2.1.txt index dd172a1a89..1a5fda3d4b 100644 --- a/docs/releases/4.2.1.txt +++ b/docs/releases/4.2.1.txt @@ -22,3 +22,6 @@ Bugfixes * Reallowed, following a regression in Django 4.2, setting the ``"cursor_factory"`` option in :setting:`OPTIONS` on PostgreSQL (:ticket:`34466`). + +* Enforced UTF-8 client encoding on PostgreSQL, following a regression in + Django 4.2 (:ticket:`34470`). diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py index 5589daa0c2..9c4512be24 100644 --- a/tests/backends/postgresql/tests.py +++ b/tests/backends/postgresql/tests.py @@ -323,6 +323,18 @@ class Tests(TestCase): finally: new_connection.close() + def test_client_encoding_utf8_enforce(self): + new_connection = connection.copy() + new_connection.settings_dict["OPTIONS"]["client_encoding"] = "iso-8859-2" + try: + new_connection.connect() + if is_psycopg3: + self.assertEqual(new_connection.connection.info.encoding, "utf-8") + else: + self.assertEqual(new_connection.connection.encoding, "UTF8") + finally: + new_connection.close() + def _select(self, val): with connection.cursor() as cursor: cursor.execute("SELECT %s::text[]", (val,)) |
