Skip to content

Commit

Permalink
Fix unexpected 'decode' AttributeError when MySQLdb module is mapped …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
ZEALi authored Apr 11, 2024
1 parent f7b10db commit 32fbd35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fix unexpected 'No active span' IllegalStateError (#311)
- **Tentative**: Set upper bound <=5.9.5 for psutil package due to test failure. (#326)
- Remove `DeprecationWarning` from `pkg_resources` by replace it with `importlib_metadata` (#329)
- Fix unexpected 'decode' AttributeError when MySQLdb module is mapped by PyMySQL (#336)

### 1.0.1

Expand Down
3 changes: 3 additions & 0 deletions skywalking/plugins/sw_mysqlclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def install():
import wrapt
import MySQLdb

if hasattr(MySQLdb, 'install_as_MySQLdb'):
raise ImportError('SKIP MySQLdb module mapped by PyMySQL', name='MySQLdb', path='')

_connect = MySQLdb.connect

def _sw_connect(*args, **kwargs):
Expand Down

0 comments on commit 32fbd35

Please sign in to comment.