summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/base.py
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2022-12-06 11:37:25 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-06 12:48:16 +0100
commit6a2165816394ab4bb259f6171e82417e098e97a6 (patch)
tree3b0f7bb0f9c277ffd4978802e5267b23ae951083 /django/db/backends/postgresql/base.py
parent29b6a177d81b9a8d833529bebfc67ef48bda3c7f (diff)
Refs #33308 -- Modernized database wrapper in the PostgreSQL backend.
- Used connection.info instead of connection.get_parameter_status() and connection.server_info which don't exist in psycopg 3. - Set encoding using the client_encoding connection parameter instead of connection.set_client_encoding() that doesn't exist in psycopg 3. - Used the dbname connection parameter instead of deprecated alias - database.
Diffstat (limited to 'django/db/backends/postgresql/base.py')
-rw-r--r--django/db/backends/postgresql/base.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index 2758c402ab..995510bcb2 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -186,16 +186,16 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.ops.max_name_length(),
)
)
- conn_params = {}
+ conn_params = {"client_encoding": "UTF8"}
if settings_dict["NAME"]:
conn_params = {
- "database": settings_dict["NAME"],
+ "dbname": settings_dict["NAME"],
**settings_dict["OPTIONS"],
}
elif settings_dict["NAME"] is None:
# Connect to the default 'postgres' db.
settings_dict.get("OPTIONS", {}).pop("service", None)
- conn_params = {"database": "postgres", **settings_dict["OPTIONS"]}
+ conn_params = {"dbname": "postgres", **settings_dict["OPTIONS"]}
else:
conn_params = {**settings_dict["OPTIONS"]}
@@ -239,7 +239,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def ensure_timezone(self):
if self.connection is None:
return False
- conn_timezone_name = self.connection.get_parameter_status("TimeZone")
+ conn_timezone_name = self.connection.info.parameter_status("TimeZone")
timezone_name = self.timezone_name
if timezone_name and conn_timezone_name != timezone_name:
with self.connection.cursor() as cursor:
@@ -249,7 +249,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def init_connection_state(self):
super().init_connection_state()
- self.connection.set_client_encoding("UTF8")
timezone_changed = self.ensure_timezone()
if timezone_changed:
@@ -365,7 +364,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
@cached_property
def pg_version(self):
with self.temporary_connection():
- return self.connection.server_version
+ return self.connection.info.server_version
def make_debug_cursor(self, cursor):
return CursorDebugWrapper(cursor, self)