prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  DeprecationWarning in sqlalchemy integration
  At integrations/sqlalchemy.py line 28 - integration is listening for dbapi_error, this was deprecated in sqlalchemy a long time ago and should be replaced with handle_error event
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `sentry_sdk/integrations/sqlalchemy.py`
  Content:
  ```
  1 from __future__ import absolute_import
  2 
  3 from sentry_sdk._types import MYPY
  4 from sentry_sdk.hub import Hub
  5 from sentry_sdk.integrations import Integration
  6 from sentry_sdk.tracing import record_sql_queries
  7 
  8 from sqlalchemy.engine import Engine  # type: ignore
  9 from sqlalchemy.event import listen  # type: ignore
  10 
  11 if MYPY:
  12     from typing import Any
  13     from typing import ContextManager
  14     from typing import Optional
  15 
  16     from sentry_sdk.tracing import Span
  17 
  18 
  19 class SqlalchemyIntegration(Integration):
  20     identifier = "sqlalchemy"
  21 
  22     @staticmethod
  23     def setup_once():
  24         # type: () -> None
  25 
  26         listen(Engine, "before_cursor_execute", _before_cursor_execute)
  27         listen(Engine, "after_cursor_execute", _after_cursor_execute)
  28         listen(Engine, "dbapi_error", _dbapi_error)
  29 
  30 
  31 def _before_cursor_execute(
  32     conn, cursor, statement, parameters, context, executemany, *args
  33 ):
  34     # type: (Any, Any, Any, Any, Any, bool, *Any) -> None
  35     hub = Hub.current
  36     if hub.get_integration(SqlalchemyIntegration) is None:
  37         return
  38 
  39     ctx_mgr = record_sql_queries(
  40         hub,
  41         cursor,
  42         statement,
  43         parameters,
  44         paramstyle=context and context.dialect and context.dialect.paramstyle or None,
  45         executemany=executemany,
  46     )
  47     conn._sentry_sql_span_manager = ctx_mgr
  48 
  49     span = ctx_mgr.__enter__()
  50 
  51     if span is not None:
  52         conn._sentry_sql_span = span
  53 
  54 
  55 def _after_cursor_execute(conn, cursor, statement, *args):
  56     # type: (Any, Any, Any, *Any) -> None
  57     ctx_mgr = getattr(
  58         conn, "_sentry_sql_span_manager", None
  59     )  # type: ContextManager[Any]
  60 
  61     if ctx_mgr is not None:
  62         conn._sentry_sql_span_manager = None
  63         ctx_mgr.__exit__(None, None, None)
  64 
  65 
  66 def _dbapi_error(conn, *args):
  67     # type: (Any, *Any) -> None
  68     span = getattr(conn, "_sentry_sql_span", None)  # type: Optional[Span]
  69 
  70     if span is not None:
  71         span.set_status("internal_error")
  72
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/sentry_sdk/integrations/sqlalchemy.py b/sentry_sdk/integrations/sqlalchemy.py
  --- a/sentry_sdk/integrations/sqlalchemy.py
  +++ b/sentry_sdk/integrations/sqlalchemy.py
  @@ -25,7 +25,7 @@
   
           listen(Engine, "before_cursor_execute", _before_cursor_execute)
           listen(Engine, "after_cursor_execute", _after_cursor_execute)
  -        listen(Engine, "dbapi_error", _dbapi_error)
  +        listen(Engine, "handle_error", _handle_error)
   
   
   def _before_cursor_execute(
  @@ -63,8 +63,9 @@
           ctx_mgr.__exit__(None, None, None)
   
   
  -def _dbapi_error(conn, *args):
  +def _handle_error(context, *args):
       # type: (Any, *Any) -> None
  +    conn = context.connection
       span = getattr(conn, "_sentry_sql_span", None)  # type: Optional[Span]
   
       if span is not None:
  
verification_info: {"golden_diff": "diff --git a/sentry_sdk/integrations/sqlalchemy.py b/sentry_sdk/integrations/sqlalchemy.py\n--- a/sentry_sdk/integrations/sqlalchemy.py\n+++ b/sentry_sdk/integrations/sqlalchemy.py\n@@ -25,7 +25,7 @@\n \n         listen(Engine, \"before_cursor_execute\", _before_cursor_execute)\n         listen(Engine, \"after_cursor_execute\", _after_cursor_execute)\n-        listen(Engine, \"dbapi_error\", _dbapi_error)\n+        listen(Engine, \"handle_error\", _handle_error)\n \n \n def _before_cursor_execute(\n@@ -63,8 +63,9 @@\n         ctx_mgr.__exit__(None, None, None)\n \n \n-def _dbapi_error(conn, *args):\n+def _handle_error(context, *args):\n     # type: (Any, *Any) -> None\n+    conn = context.connection\n     span = getattr(conn, \"_sentry_sql_span\", None)  # type: Optional[Span]\n \n     if span is not None:\n", "issue": "DeprecationWarning in sqlalchemy integration\nAt integrations/sqlalchemy.py line 28 - integration is listening for dbapi_error, this was deprecated in sqlalchemy a long time ago and should be replaced with handle_error event\n", "before_files": [{"content": "from __future__ import absolute_import\n\nfrom sentry_sdk._types import MYPY\nfrom sentry_sdk.hub import Hub\nfrom sentry_sdk.integrations import Integration\nfrom sentry_sdk.tracing import record_sql_queries\n\nfrom sqlalchemy.engine import Engine  # type: ignore\nfrom sqlalchemy.event import listen  # type: ignore\n\nif MYPY:\n    from typing import Any\n    from typing import ContextManager\n    from typing import Optional\n\n    from sentry_sdk.tracing import Span\n\n\nclass SqlalchemyIntegration(Integration):\n    identifier = \"sqlalchemy\"\n\n    @staticmethod\n    def setup_once():\n        # type: () -> None\n\n        listen(Engine, \"before_cursor_execute\", _before_cursor_execute)\n        listen(Engine, \"after_cursor_execute\", _after_cursor_execute)\n        listen(Engine, \"dbapi_error\", _dbapi_error)\n\n\ndef _before_cursor_execute(\n    conn, cursor, statement, parameters, context, executemany, *args\n):\n    # type: (Any, Any, Any, Any, Any, bool, *Any) -> None\n    hub = Hub.current\n    if hub.get_integration(SqlalchemyIntegration) is None:\n        return\n\n    ctx_mgr = record_sql_queries(\n        hub,\n        cursor,\n        statement,\n        parameters,\n        paramstyle=context and context.dialect and context.dialect.paramstyle or None,\n        executemany=executemany,\n    )\n    conn._sentry_sql_span_manager = ctx_mgr\n\n    span = ctx_mgr.__enter__()\n\n    if span is not None:\n        conn._sentry_sql_span = span\n\n\ndef _after_cursor_execute(conn, cursor, statement, *args):\n    # type: (Any, Any, Any, *Any) -> None\n    ctx_mgr = getattr(\n        conn, \"_sentry_sql_span_manager\", None\n    )  # type: ContextManager[Any]\n\n    if ctx_mgr is not None:\n        conn._sentry_sql_span_manager = None\n        ctx_mgr.__exit__(None, None, None)\n\n\ndef _dbapi_error(conn, *args):\n    # type: (Any, *Any) -> None\n    span = getattr(conn, \"_sentry_sql_span\", None)  # type: Optional[Span]\n\n    if span is not None:\n        span.set_status(\"internal_error\")\n", "path": "sentry_sdk/integrations/sqlalchemy.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\nfrom sentry_sdk._types import MYPY\nfrom sentry_sdk.hub import Hub\nfrom sentry_sdk.integrations import Integration\nfrom sentry_sdk.tracing import record_sql_queries\n\nfrom sqlalchemy.engine import Engine  # type: ignore\nfrom sqlalchemy.event import listen  # type: ignore\n\nif MYPY:\n    from typing import Any\n    from typing import ContextManager\n    from typing import Optional\n\n    from sentry_sdk.tracing import Span\n\n\nclass SqlalchemyIntegration(Integration):\n    identifier = \"sqlalchemy\"\n\n    @staticmethod\n    def setup_once():\n        # type: () -> None\n\n        listen(Engine, \"before_cursor_execute\", _before_cursor_execute)\n        listen(Engine, \"after_cursor_execute\", _after_cursor_execute)\n        listen(Engine, \"handle_error\", _handle_error)\n\n\ndef _before_cursor_execute(\n    conn, cursor, statement, parameters, context, executemany, *args\n):\n    # type: (Any, Any, Any, Any, Any, bool, *Any) -> None\n    hub = Hub.current\n    if hub.get_integration(SqlalchemyIntegration) is None:\n        return\n\n    ctx_mgr = record_sql_queries(\n        hub,\n        cursor,\n        statement,\n        parameters,\n        paramstyle=context and context.dialect and context.dialect.paramstyle or None,\n        executemany=executemany,\n    )\n    conn._sentry_sql_span_manager = ctx_mgr\n\n    span = ctx_mgr.__enter__()\n\n    if span is not None:\n        conn._sentry_sql_span = span\n\n\ndef _after_cursor_execute(conn, cursor, statement, *args):\n    # type: (Any, Any, Any, *Any) -> None\n    ctx_mgr = getattr(\n        conn, \"_sentry_sql_span_manager\", None\n    )  # type: ContextManager[Any]\n\n    if ctx_mgr is not None:\n        conn._sentry_sql_span_manager = None\n        ctx_mgr.__exit__(None, None, None)\n\n\ndef _handle_error(context, *args):\n    # type: (Any, *Any) -> None\n    conn = context.connection\n    span = getattr(conn, \"_sentry_sql_span\", None)  # type: Optional[Span]\n\n    if span is not None:\n        span.set_status(\"internal_error\")\n", "path": "sentry_sdk/integrations/sqlalchemy.py"}]}