8000 Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment · Issue #237 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content
Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment #237
Closed
@seanh

Description

@seanh

Is before_send broken?

If I add a before_send:

def _before_send(event, hint):
    return event

sentry_sdk.init(
    integrations=[
        sentry_sdk.integrations.celery.CeleryIntegration(),
        sentry_sdk.integrations.pyramid.PyramidIntegration(),
    ],
    environment="dev",
    send_default_pii=True,
    before_send=_before_send,
)

then if my Pyramid application raises an exception, e.g:

raise RuntimeError("Argh")

then sentry_sdk appears to crash when trying to report the exception to Sentry:

Traceback (most recent call last):
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_debugtoolbar/toolbar.py", line 257, in toolbar_tween
    response = _handler(request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_debugtoolbar/panels/performance.py", line 58, in resource_timer_handler
    result = handler(request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/tweens.py", line 51, in excview_tween
    request_iface=request_iface.combined
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/view.py", line 547, in _call_view
    response = view_callable(context, request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/config/views.py", line 182, in __call__
    return view(context, request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py", line 393, in attr_view
    return view(context, request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py", line 371, in predicate_wrapper
    return view(context, request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py", line 330, in _authdebug_view
    return view(context, request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py", line 442, in rendered_view
    result = view(context, request)
  File "/home/seanh/Projects/h/h/views/errors.py", line 33, in error
    handle_exception(request, exception=context)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 119, in tm_tween
    reraise(*exc_info)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 98, in tm_tween
    response = handler(request)
  File "/home/seanh/Projects/h/h/tweens.py", line 22, in conditional_http_tween
    response = handler(request)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/integrations/pyramid.py", line 53, in sentry_patched_handle_request
    _capture_exception(exc_info)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/integrations/pyramid.py", line 85, in _capture_exception
    hub.capture_event(event, hint=hint)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/hub.py", line 224, in capture_event
    rv = client.capture_event(event, hint, scope)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/client.py", line 190, in capture_event
    event = self._prepare_event(event, hint, scope)
  File "/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/client.py", line 125, in _prepare_event
    if new_event is None:
UnboundLocalError: local variable 'new_event' referenced before assignment

Here's the actual code in my app that's producing this crash: hypothesis/h#5497

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0