diff options
| author | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-08-19 16:51:31 +0200 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2024-08-28 19:25:07 -0300 |
| commit | 7380ac57340653854bc2cfe0ed80298cdac6061d (patch) | |
| tree | e6b8bbf2d73078e126001b59c409fedb0e40101b /tests/backends/postgresql | |
| parent | 26a67943ac5c2f196621220b24f4314d84471d07 (diff) | |
Fixed #35688 -- Restored timezone and role setters to be PostgreSQL DatabaseWrapper methods.
Following the addition of PostgreSQL connection pool support in
Refs #33497, the methods for configuring the database role and timezone
were moved to module-level functions. This change prevented subclasses
of DatabaseWrapper from overriding these methods as needed, for example,
when creating wrappers for other PostgreSQL-based backends.
Thank you Christian Hardenberg for the report and to
Florian Apolloner and Natalia Bidart for the review.
Regression in fad334e1a9b54ea1acb8cce02a25934c5acfe99f.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Diffstat (limited to 'tests/backends/postgresql')
| -rw-r--r-- | tests/backends/postgresql/tests.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py index 0b4f580612..37c5ee562b 100644 --- a/tests/backends/postgresql/tests.py +++ b/tests/backends/postgresql/tests.py @@ -567,3 +567,49 @@ class Tests(TestCase): ) finally: new_connection.close() + + def test_bypass_timezone_configuration(self): + from django.db.backends.postgresql.base import DatabaseWrapper + + class CustomDatabaseWrapper(DatabaseWrapper): + def _configure_timezone(self, connection): + return False + + for Wrapper, commit in [ + (DatabaseWrapper, True), + (CustomDatabaseWrapper, False), + ]: + with self.subTest(wrapper=Wrapper, commit=commit): + new_connection = no_pool_connection() + self.addCleanup(new_connection.close) + + # Set the database default time zone to be different from + # the time zone in new_connection.settings_dict. + with new_connection.cursor() as cursor: + cursor.execute("RESET TIMEZONE") + cursor.execute("SHOW TIMEZONE") + db_default_tz = cursor.fetchone()[0] + new_tz = "Europe/Paris" if db_default_tz == "UTC" else "UTC" + new_connection.timezone_name = new_tz + + settings = new_connection.settings_dict.copy() + conn = new_connection.connection + self.assertIs(Wrapper(settings)._configure_connection(conn), commit) + + def test_bypass_role_configuration(self): + from django.db.backends.postgresql.base import DatabaseWrapper + + class CustomDatabaseWrapper(DatabaseWrapper): + def _configure_role(self, connection): + return False + + new_connection = no_pool_connection() + self.addCleanup(new_connection.close) + new_connection.connect() + + settings = new_connection.settings_dict.copy() + settings["OPTIONS"]["assume_role"] = "django_nonexistent_role" + conn = new_connection.connection + self.assertIs( + CustomDatabaseWrapper(settings)._configure_connection(conn), False + ) |
