#35688 closed Bug (fixed)
Postgresql DatabaseWrapper does not allow to override ensure_timezone() function in derived classes
Reported by: | Christian Hardenberg | Owned by: | Sarah Boyce |
---|---|---|---|
Component: | contrib.postgres | Version: | 5.1 |
Severity: | Release blocker | Keywords: | DatabaseWrapper posgresql ensure_timezone |
Cc: | Christian Hardenberg, Florian Apolloner | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Description:
The function _configure_connection() in base.py of the postgresql DatabaseWrapper directly calls the local function ensure_timezone:
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:
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)")
Change History (8)
comment:1 by , 3 months ago
Cc: | added |
---|---|
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 3 months ago
Yes we can make it a class method (and init_connection_state + ensure_role) as well. Please ping me for a review once a PR is up.
comment:3 by , 3 months ago
Easy pickings: | unset |
---|---|
Has patch: | set |
Owner: | set to |
Status: | new → assigned |
I haven't updated ensure_role to be a class method but I can
comment:4 by , 2 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 2 months ago
Triage Stage: | Ready for checkin → Accepted |
---|
comment:6 by , 2 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Thank you! Agree we should make some kinda update here
Regression in fad334e1a9b54ea1acb8cce02a25934c5acfe99f (ref #33497)
Would you like to prepare a PR?