Bandit fixes

also brings the exception-handling of apply_sourcemaps inline
w/ issues/views.py (as promised per the module header)
This commit is contained in:
Klaas van Schelven
2025-09-15 16:29:06 +02:00
parent d3fd513e43
commit 4d18008cd8
2 changed files with 16 additions and 4 deletions

View File

@@ -10,9 +10,14 @@
# The provided markdown is not a stable interface; it's intended to be useful but not something you'd parse
# programmatically (just use the event data instead).
import logging
from django.conf import settings
from events.utils import apply_sourcemaps
from sentry_sdk_extensions import capture_or_log_exception
logger = logging.getLogger("bugsink.issues")
def _code_segments(frame):
pre = frame.get("pre_context") or []
@@ -132,8 +137,13 @@ def render_stacktrace_md(event, frames="in_app", include_locals=True):
parsed = event.get_parsed_data()
try:
apply_sourcemaps(parsed)
except Exception:
pass
except Exception as e:
if settings.DEBUG or settings.I_AM_RUNNING == "TEST":
# when developing/testing, I _do_ want to get notified
raise
# sourcemaps are still experimental; we don't want to fail on them, so we just log the error and move on.
capture_or_log_exception(e, logger)
excs = _iter_exceptions(parsed)
if not excs:

View File

@@ -5,6 +5,7 @@ from rest_framework.exceptions import ValidationError
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes
from bugsink.api_mixins import AtomicRequestMixin
from bugsink.utils import assert_
from .models import Issue
from .serializers import IssueSerializer
@@ -120,7 +121,8 @@ class IssueViewSet(AtomicRequestMixin, viewsets.ReadOnlyModelViewSet):
queryset = self.get_queryset()
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
assert lookup_url_kwarg in self.kwargs, (
assert_(
lookup_url_kwarg in self.kwargs,
'Expected view %s to be called with a URL keyword argument named "%s".'
% (self.__class__.__name__, lookup_url_kwarg)
)