From afdd93a1c5c0c40d10951adc26bb3ceae63502be Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 13 Nov 2024 14:07:00 +0900 Subject: [PATCH 1/6] ci: fix django test (#746) --- ci/test_mysql.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/test_mysql.py b/ci/test_mysql.py index 9417fc9f..498be7cf 100644 --- a/ci/test_mysql.py +++ b/ci/test_mysql.py @@ -39,3 +39,5 @@ ] DEFAULT_AUTO_FIELD = "django.db.models.AutoField" + +USE_TZ = False From 49e44c5b469a5abf81731b45ad0eb257376a718e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:04:55 +0900 Subject: [PATCH 2/6] chore(deps): update codecov/codecov-action action to v5 (#747) --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8156fccc..cf784c78 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -59,7 +59,7 @@ jobs: run: | pytest --cov=MySQLdb tests - - uses: codecov/codecov-action@v4 + - uses: codecov/codecov-action@v5 django-test: name: "Run Django LTS test suite" From 207ac1a948a3e4ae31ceadb78d08bf83bd2f2520 Mon Sep 17 00:00:00 2001 From: Cristi Fati Date: Sat, 14 Dec 2024 04:06:06 +0200 Subject: [PATCH 3/6] windows: add MariaDB include paths (#749) --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 771b39b4..9a1d26b8 100644 --- a/setup.py +++ b/setup.py @@ -109,6 +109,7 @@ def get_config_win32(options): ] include_dirs = [ os.path.join(connector, "include", "mariadb"), + os.path.join(connector, "include", "mysql"), os.path.join(connector, "include"), ] From 8103651bffbf0ee890d2731d4e1fae1f80a50661 Mon Sep 17 00:00:00 2001 From: Mikhail Chinkov Date: Sun, 5 Jan 2025 05:17:09 +0100 Subject: [PATCH 4/6] 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 73c95e0f..c3575454 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]] ) From 2226fc471930a73f59985ab48b6f54e76c865eac Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 10 Jan 2025 20:18:31 +0900 Subject: [PATCH 5/6] support opentelemetry-instrumentation (#753) --- src/MySQLdb/connections.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/MySQLdb/connections.py b/src/MySQLdb/connections.py index c3575454..5bcfc937 100644 --- a/src/MySQLdb/connections.py +++ b/src/MySQLdb/connections.py @@ -196,20 +196,18 @@ class object, used to create cursors (keyword only) # PEP-249 requires autocommit to be initially off autocommit = kwargs2.pop("autocommit", False) + self._set_attributes(*args, **kwargs2) super().__init__(*args, **kwargs2) + self.cursorclass = cursorclass self.encoders = { k: v for k, v in conv.items() 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]] ) - self.encoding = "ascii" # overridden in set_character_set() if not charset: @@ -240,6 +238,21 @@ class object, used to create cursors (keyword only) self.autocommit(autocommit) self.messages = [] + def _set_attributes(self, host=None, user=None, password=None, database="", port=3306, + unix_socket=None, **kwargs): + """set some attributes for otel""" + if unix_socket and not host: + host = "localhost" + # support opentelemetry-instrumentation-dbapi + self.host = host + # _mysql.Connection provides self.port + self.user = user + self.database = database + # otel-inst-mysqlclient uses db instead of database. + self.db = database + # NOTE: We have not supported semantic conventions yet. + # https://opentelemetry.io/docs/specs/semconv/database/sql/ + def __enter__(self): return self From 2076d161e2f09f3fb99e00134c9f415063924ad9 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 10 Jan 2025 20:45:32 +0900 Subject: [PATCH 6/6] release v2.2.7 (#754) --- HISTORY.rst | 9 +++++++++ src/MySQLdb/release.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index bc95c774..66470541 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,3 +1,12 @@ +====================== + What's new in 2.2.7 +====================== + +Release: 2025-01-10 + +* Add ``user``, ``host``, ``database``, and ``db`` attributes to ``Connection``. + opentelemetry-instrumentation-(dbapi|mysqlclient) use them. (#753) + ====================== What's new in 2.2.6 ====================== diff --git a/src/MySQLdb/release.py b/src/MySQLdb/release.py index 0b168441..234d9958 100644 --- a/src/MySQLdb/release.py +++ b/src/MySQLdb/release.py @@ -1,3 +1,3 @@ __author__ = "Inada Naoki " -__version__ = "2.2.6" -version_info = (2, 2, 6, "final", 0) +__version__ = "2.2.7" +version_info = (2, 2, 7, "final", 0)