From bbc8b7c90d58720b8f88c410a09ff0c876d77329 Mon Sep 17 00:00:00 2001 From: SB-PawanN Date: Wed, 1 Apr 2026 15:12:49 +0530 Subject: [PATCH 1/4] Changes done in except block to catch errors. --- bugsnag/legacy.py | 57 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/bugsnag/legacy.py b/bugsnag/legacy.py index 32848b52..83c6406e 100644 --- a/bugsnag/legacy.py +++ b/bugsnag/legacy.py @@ -1,6 +1,7 @@ from typing import Dict, Any, Tuple, Type, Optional, Union, List, Callable import types import sys +import warnings from bugsnag.breadcrumbs import BreadcrumbType, OnBreadcrumbCallback from bugsnag.feature_flags import FeatureFlag @@ -13,16 +14,64 @@ ExcInfoType = Tuple[Type, Exception, types.TracebackType] -__all__ = ('configure', 'configure_request', 'add_metadata_tab', - 'clear_request_config', 'notify', 'start_session', 'auto_notify', - 'auto_notify_exc_info', 'before_notify', 'leave_breadcrumb') +__all__ = ( + 'configure', + 'configure_request', + 'add_metadata_tab', + 'clear_request_config', + 'notify', + 'start_session', + 'auto_notify', + 'auto_notify_exc_info', + 'before_notify', + 'leave_breadcrumb', +) def configure(**options): """ Configure the Bugsnag notifier application-wide settings. """ - return configuration.configure(**options) + # Synchronize legacy references to point at the live configuration + # only `logger` is rebound in this scope + global logger + + # Delegate to the module-local configuration instance so we update the + # single source of truth without resolving package submodules that may + # shadow the attribute name. + result = configuration.configure(**options) + try: + default_client.configuration = configuration + except (AttributeError, TypeError, ImportError) as exc: + try: + configuration.logger.debug( + "legacy configuration sync failed: %s", exc + ) + except Exception: + warnings.warn( + f"legacy configuration sync failed: {exc}", stacklevel=2 + ) + + logger = configuration.logger + + # Also update the `bugsnag` package attributes so other modules that + # reference `bugsnag.configuration` / `bugsnag.logger` reflect the + # live configuration object (keeps package-level attributes in sync). + try: + import bugsnag as _pkg + setattr(_pkg, 'configuration', configuration) + setattr(_pkg, 'logger', configuration.logger) + except (ImportError, AttributeError, TypeError) as exc: + try: + configuration.logger.debug( + "legacy package attr sync failed: %s", exc + ) + except Exception: + warnings.warn( + f"legacy package attr sync failed: {exc}", stacklevel=2 + ) + + return result def configure_request(**options): From 184920d2bc69e23e03407c705511dce9722531f7 Mon Sep 17 00:00:00 2001 From: SB-PawanN Date: Wed, 1 Apr 2026 16:05:30 +0530 Subject: [PATCH 2/4] supporting changes --- tests/test_legacy_configuration.py | 13 +++++++++++++ tox.ini | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/test_legacy_configuration.py diff --git a/tests/test_legacy_configuration.py b/tests/test_legacy_configuration.py new file mode 100644 index 00000000..2be72312 --- /dev/null +++ b/tests/test_legacy_configuration.py @@ -0,0 +1,13 @@ +import bugsnag +from bugsnag import legacy + + +def test_legacy_configuration_sync(): + """After calling `bugsnag.configure(...)`, the package and legacy + configuration objects should point to the same live objects. + This prevents an import-time snapshot from becoming stale. + """ + bugsnag.configure(api_key="test-api-key") + + assert bugsnag.configuration is legacy.configuration + assert getattr(bugsnag, "logger", None) is getattr(legacy, "logger", None) diff --git a/tox.ini b/tox.ini index 20ec3042..e3ed44af 100644 --- a/tox.ini +++ b/tox.ini @@ -43,8 +43,9 @@ deps= requests: requests wsgi: webtest asgi: starlette + asgi: starlette<0.28 asgi: requests - asgi: httpx + asgi: httpx<0.28 bottle: webtest bottle: bottle flask: flask From e530acb05d77b4198ae7c0589db2e2712cf41bd5 Mon Sep 17 00:00:00 2001 From: SB-PawanN Date: Wed, 1 Apr 2026 16:33:33 +0530 Subject: [PATCH 3/4] maze-runner (3.5) - supporting changes. --- bugsnag/legacy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bugsnag/legacy.py b/bugsnag/legacy.py index 83c6406e..c7c0944e 100644 --- a/bugsnag/legacy.py +++ b/bugsnag/legacy.py @@ -49,7 +49,7 @@ def configure(**options): ) except Exception: warnings.warn( - f"legacy configuration sync failed: {exc}", stacklevel=2 + "legacy configuration sync failed: {}".format(exc), stacklevel=2 ) logger = configuration.logger @@ -68,7 +68,7 @@ def configure(**options): ) except Exception: warnings.warn( - f"legacy package attr sync failed: {exc}", stacklevel=2 + "legacy package attr sync failed: {}".format(exc), stacklevel=2 ) return result From 5ccf47a3c0d479428d8bab50d6031cb32630ff54 Mon Sep 17 00:00:00 2001 From: SB-PawanN Date: Wed, 1 Apr 2026 20:24:53 +0530 Subject: [PATCH 4/4] Error caused by the flake8 E501 in legacy.py (line too long). Splitting that long warnings.warn(...) call fixed the lint error in local. --- bugsnag/legacy.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bugsnag/legacy.py b/bugsnag/legacy.py index c7c0944e..979c7282 100644 --- a/bugsnag/legacy.py +++ b/bugsnag/legacy.py @@ -49,7 +49,8 @@ def configure(**options): ) except Exception: warnings.warn( - "legacy configuration sync failed: {}".format(exc), stacklevel=2 + "legacy configuration sync failed: {}".format(exc), + stacklevel=2 ) logger = configuration.logger @@ -68,7 +69,8 @@ def configure(**options): ) except Exception: warnings.warn( - "legacy package attr sync failed: {}".format(exc), stacklevel=2 + "legacy package attr sync failed: {}".format(exc), + stacklevel=2 ) return result