From 8103651bffbf0ee890d2731d4e1fae1f80a50661 Mon Sep 17 00:00:00 2001 From: Mikhail Chinkov Date: Sun, 5 Jan 2025 05:17:09 +0100 Subject: [PATCH] add database name as the Connection attribute (#752) This change adds `self.database` as the Connection attribute displaying the database name from connection parameters. This is very useful for otel dbapi tracer. --- src/MySQLdb/connections.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MySQLdb/connections.py b/src/MySQLdb/connections.py index 73c95e0..c357545 100644 --- a/src/MySQLdb/connections.py +++ b/src/MySQLdb/connections.py @@ -204,6 +204,8 @@ class object, used to create cursors (keyword only) if type(k) is not int # noqa: E721 } + self.database = kwargs2.get("database", "") + self._server_version = tuple( [numeric_part(n) for n in self.get_server_info().split(".")[:2]] )