Skip to content

Commit 32fbd35

Browse files
authored
Fix unexpected 'decode' AttributeError when MySQLdb module is mapped by PyMySQL (#336)
* Skip if MySQLdb module is mapped by PyMySQL In some use cases, `pymysql.install_as_MySQLdb()` will be used to initialize a 'fake' MySQLdb module, which is actually mapped to pymysql module. Then the sw_mysqlclient plugin will change the data type of `connection.db` from bytes into str, cause the `AttributeError: 'str' object has no attribute 'decode'` exception in sw_pymysql.py line 45, which regard it as bytes.
1 parent f7b10db commit 32fbd35

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Fix unexpected 'No active span' IllegalStateError (#311)
1414
- **Tentative**: Set upper bound <=5.9.5 for psutil package due to test failure. (#326)
1515
- Remove `DeprecationWarning` from `pkg_resources` by replace it with `importlib_metadata` (#329)
16+
- Fix unexpected 'decode' AttributeError when MySQLdb module is mapped by PyMySQL (#336)
1617

1718
### 1.0.1
1819

skywalking/plugins/sw_mysqlclient.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def install():
3232
import wrapt
3333
import MySQLdb
3434

35+
if hasattr(MySQLdb, 'install_as_MySQLdb'):
36+
raise ImportError('SKIP MySQLdb module mapped by PyMySQL', name='MySQLdb', path='')
37+
3538
_connect = MySQLdb.connect
3639

3740
def _sw_connect(*args, **kwargs):

0 commit comments

Comments
 (0)