mirror of
https://github.com/django/django.git
synced 2025-09-15 15:05:14 +00:00
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 fad334e1a9
.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
This commit is contained in:
parent
26a67943ac
commit
7380ac5734
3 changed files with 71 additions and 25 deletions
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue