From 92e24b45d14b331d97eada45fdc617f07e46d378 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova <131587164+sentrivana@users.noreply.github.com> Date: Thu, 4 May 2023 12:09:31 +0200 Subject: [PATCH] Handle sqlalchemy engine.name being bytes (#2074) --- sentry_sdk/integrations/sqlalchemy.py | 3 +++ tests/integrations/sqlalchemy/test_sqlalchemy.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/sentry_sdk/integrations/sqlalchemy.py b/sentry_sdk/integrations/sqlalchemy.py index 2d6018d732..5c5adec86d 100644 --- a/sentry_sdk/integrations/sqlalchemy.py +++ b/sentry_sdk/integrations/sqlalchemy.py @@ -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 @@ -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" diff --git a/tests/integrations/sqlalchemy/test_sqlalchemy.py b/tests/integrations/sqlalchemy/test_sqlalchemy.py index ebd83f42fb..edeab6e983 100644 --- a/tests/integrations/sqlalchemy/test_sqlalchemy.py +++ b/tests/integrations/sqlalchemy/test_sqlalchemy.py @@ -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")