Skip to content

Commit

Permalink
Handle sqlalchemy engine.name being bytes (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana authored May 4, 2023
1 parent 019f10c commit 92e24b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sentry_sdk/integrations/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import re

from sentry_sdk._compat import text_type
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.consts import SPANDATA
from sentry_sdk.hub import Hub
Expand Down Expand Up @@ -111,6 +112,8 @@ def _handle_error(context, *args):
# See: https://docs.sqlalchemy.org/en/20/dialects/index.html
def _get_db_system(name):
# type: (str) -> Optional[str]
name = text_type(name)

if "sqlite" in name:
return "sqlite"

Expand Down
12 changes: 12 additions & 0 deletions tests/integrations/sqlalchemy/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,15 @@ def processor(event, hint):
assert event["_meta"]["message"] == {
"": {"len": 1034, "rem": [["!limit", "x", 1021, 1024]]}
}


def test_engine_name_not_string(sentry_init):
sentry_init(
integrations=[SqlalchemyIntegration()],
)

engine = create_engine("sqlite:///:memory:")
engine.dialect.name = b"sqlite"

with engine.connect() as con:
con.execute("SELECT 0")

0 comments on commit 92e24b4

Please sign in to comment.