#35688: Postgresql DatabaseWrapper does not allow to override ensure_timezone()
function in derived classes
-------------------------------------+-------------------------------------
Reporter: chardenberg | Type: Bug
Status: new | Component:
| contrib.postgres
Version: 5.1 | Severity: Normal
Keywords: DatabaseWrapper | Triage Stage:
posgresql ensure_timezone | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
**Description:**
The function _configure_connection() in base.py of the postgresql
DatabaseWrapper directly calls the local function ensure_timezone:
{{{#!python
def _configure_connection(self, connection):
# This function is called from init_connection_state and from the
# psycopg pool itself after a connection is opened. Make sure that
# whatever is done here does not access anything on self aside
from
# variables.
# Commit after setting the time zone.
commit_tz = ensure_timezone(connection, self.ops,
self.timezone_name)
# Set the role on the connection. This is useful if the credential
used
# to login is not the same as the role that owns database
resources. As
# can be the case when using temporary or ephemeral credentials.
role_name = self.settings_dict["OPTIONS"].get("assume_role")
commit_role = ensure_role(connection, self.ops, role_name)
return commit_role or commit_tz
}}}
Instead it should call the class method like this, which should have the
same result, but allows overriding in derived classes:
{{{#!python
commit_tz = self.ensure_timezone()
}}}
**Why it matters?**
I am implementing a database wrapper for QuestDB, which implements the
postgres-protocol, so it's useful to derive the wrapper from the postgres
wrapper. I need to override some methods though, such as ensure_timezone,
because the set_config function is not supported by QuestDB ("SELECT
set_config('TimeZone', 'UTC', false)")
--
Ticket URL: <
https://code.djangoproject.com/ticket/35688>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.