Skip to content

Commit 92e24b4

Browse files
authored
Handle sqlalchemy engine.name being bytes (#2074)
1 parent 019f10c commit 92e24b4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

sentry_sdk/integrations/sqlalchemy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import re
44

5+
from sentry_sdk._compat import text_type
56
from sentry_sdk._types import TYPE_CHECKING
67
from sentry_sdk.consts import SPANDATA
78
from sentry_sdk.hub import Hub
@@ -111,6 +112,8 @@ def _handle_error(context, *args):
111112
# See: https://docs.sqlalchemy.org/en/20/dialects/index.html
112113
def _get_db_system(name):
113114
# type: (str) -> Optional[str]
115+
name = text_type(name)
116+
114117
if "sqlite" in name:
115118
return "sqlite"
116119

tests/integrations/sqlalchemy/test_sqlalchemy.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,15 @@ def processor(event, hint):
208208
assert event["_meta"]["message"] == {
209209
"": {"len": 1034, "rem": [["!limit", "x", 1021, 1024]]}
210210
}
211+
212+
213+
def test_engine_name_not_string(sentry_init):
214+
sentry_init(
215+
integrations=[SqlalchemyIntegration()],
216+
)
217+
218+
engine = create_engine("sqlite:///:memory:")
219+
engine.dialect.name = b"sqlite"
220+
221+
with engine.connect() as con:
222+
con.execute("SELECT 0")

0 commit comments

Comments
 (0)