Skip to content

Commit 1fde425

Browse files
authored
instrumentation/mysql_connector: fix connection retrieval (#2344)
The code was not working becase there was no default on getattr calls.
1 parent e4dff95 commit 1fde425

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

elasticapm/instrumentation/packages/mysql_connector.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ def extract_signature(self, sql):
4646

4747
@property
4848
def _self_database(self) -> str:
49-
# for unknown reasons, the connection is available as the `_connection` attribute on Python 3.6,
50-
# and as `_cnx` on later Python versions
51-
connection = getattr(self, "_cnx") or getattr(self, "_connection")
49+
# it looks like the connection is available as the `_connection` or as `_cnx` depending on Python versions
50+
connection = getattr(self, "_connection", None) or getattr(self, "_cnx", None)
5251
return connection.database if connection else ""
5352

5453

tests/instrumentation/mysql_connector_tests.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ def mysql_connector_connection(request):
6363
cursor.execute("DROP TABLE `test`")
6464

6565

66-
@pytest.mark.skipif(
67-
sys.version_info >= (3, 12), reason="Perhaps related to changes in weakref in py3.12?"
68-
) # TODO py3.12
6966
@pytest.mark.integrationtest
7067
def test_mysql_connector_select(instrument, mysql_connector_connection, elasticapm_client):
7168
cursor = mysql_connector_connection.cursor()

0 commit comments

Comments
 (0)