René's URL Explorer Experiment


Title: Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment · Issue #237 · getsentry/sentry-python · GitHub

Open Graph Title: Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment · Issue #237 · getsentry/sentry-python

X Title: Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment · Issue #237 · getsentry/sentry-python

Description: 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(), ], envir...

Open Graph Description: 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.integration...

X Description: 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.integration...

Opengraph URL: https://github.com/getsentry/sentry-python/issues/237

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignment","articleBody":"Is `before_send` broken?\r\n\r\nIf I add a `before_send`:\r\n\r\n```python\r\ndef _before_send(event, hint):\r\n    return event\r\n\r\nsentry_sdk.init(\r\n    integrations=[\r\n        sentry_sdk.integrations.celery.CeleryIntegration(),\r\n        sentry_sdk.integrations.pyramid.PyramidIntegration(),\r\n    ],\r\n    environment=\"dev\",\r\n    send_default_pii=True,\r\n    before_send=_before_send,\r\n)\r\n```\r\n\r\nthen if my Pyramid application raises an exception, e.g:\r\n\r\n```python\r\nraise RuntimeError(\"Argh\")\r\n```\r\n\r\nthen `sentry_sdk` appears to crash when trying to report the exception to Sentry:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_debugtoolbar/toolbar.py\", line 257, in toolbar_tween\r\n    response = _handler(request)\r\n  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\r\n    result = handler(request)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/tweens.py\", line 51, in excview_tween\r\n    request_iface=request_iface.combined\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/view.py\", line 547, in _call_view\r\n    response = view_callable(context, request)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/config/views.py\", line 182, in __call__\r\n    return view(context, request)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py\", line 393, in attr_view\r\n    return view(context, request)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py\", line 371, in predicate_wrapper\r\n    return view(context, request)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py\", line 330, in _authdebug_view\r\n    return view(context, request)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/viewderivers.py\", line 442, in rendered_view\r\n    result = view(context, request)\r\n  File \"/home/seanh/Projects/h/h/views/errors.py\", line 33, in error\r\n    handle_exception(request, exception=context)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid/tweens.py\", line 22, in excview_tween\r\n    response = handler(request)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_tm/__init__.py\", line 119, in tm_tween\r\n    reraise(*exc_info)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/pyramid_tm/__init__.py\", line 98, in tm_tween\r\n    response = handler(request)\r\n  File \"/home/seanh/Projects/h/h/tweens.py\", line 22, in conditional_http_tween\r\n    response = handler(request)\r\n  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\r\n    _capture_exception(exc_info)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/integrations/pyramid.py\", line 85, in _capture_exception\r\n    hub.capture_event(event, hint=hint)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/hub.py\", line 224, in capture_event\r\n    rv = client.capture_event(event, hint, scope)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/client.py\", line 190, in capture_event\r\n    event = self._prepare_event(event, hint, scope)\r\n  File \"/home/seanh/Projects/h/.tox/py27-dev/local/lib/python2.7/site-packages/sentry_sdk/client.py\", line 125, in _prepare_event\r\n    if new_event is None:\r\nUnboundLocalError: local variable 'new_event' referenced before assignment\r\n```\r\n\r\nHere's the actual code in my app that's producing this crash: https://github.com/hypothesis/h/pull/5497","author":{"url":"https://github.com/seanh","@type":"Person","name":"seanh"},"datePublished":"2019-01-16T18:35:30Z","url":"https://github.com/getsentry/sentry-python/issues/237"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c363a037-25ee-237b-f3c6-a519df60b1ac
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA592:358871:39E006:4E9CED:6B00C69C
html-safe-nonce55a7c3a41fac13751646bac63261bfbf3373ae250ce438b96590b9650db1b64c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTkyOjM1ODg3MTozOUUwMDY6NEU5Q0VEOjZCMDBDNjlDIiwidmlzaXRvcl9pZCI6Ijg1NjI3ODg5NDg3ODU1NDY5MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacc39f38343fb8cbf5177bc98d7d2e1ea20fbc483ee1cf9204e55f6500b409a031
hovercard-subject-tagissue:399941409
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/237/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c90e60c3787c2279d141b8c480973805b3a5d8f0ed9cea7112ced6eed3d5e2cb/getsentry/sentry-python/issues/237
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c90e60c3787c2279d141b8c480973805b3a5d8f0ed9cea7112ced6eed3d5e2cb/getsentry/sentry-python/issues/237
og:image:altIs 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.integration...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameseanh
hostnamegithub.com
expected-hostnamegithub.com
None98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id137814779
octolytics-dimension-repository_nwogetsentry/sentry-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id137814779
octolytics-dimension-repository_network_root_nwogetsentry/sentry-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseef013399cf0a3c324bea644a685d7c1e0f06b5b7
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-python/issues/237#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-python%2Fissues%2F237
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-python%2Fissues%2F237
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-python
Reloadhttps://github.com/getsentry/sentry-python/issues/237
Reloadhttps://github.com/getsentry/sentry-python/issues/237
Reloadhttps://github.com/getsentry/sentry-python/issues/237
getsentryhttps://github.com/getsentry
sentry-pythonhttps://github.com/getsentry/sentry-python
Codehttps://github.com/getsentry/sentry-python
Issues345 (345)https://github.com/getsentry/sentry-python/issues
Pull requests42 (42)https://github.com/getsentry/sentry-python/pulls
Discussionshttps://github.com/getsentry/sentry-python/discussions
Actionshttps://github.com/getsentry/sentry-python/actions
Security and quality2 (2)https://github.com/getsentry/sentry-python/security
Insightshttps://github.com/getsentry/sentry-python/insights
https://github.com/getsentry/sentry-python
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-python/issues/237
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-python/issues/237
Using before_send causes sentry_sdk to crash? 'new_event' referenced before assignmenthttps://github.com/getsentry/sentry-python/issues/237#top
Bughttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Bug%22
https://github.com/seanh
seanhhttps://github.com/seanh
on Jan 16, 2019https://github.com/getsentry/sentry-python/issues/237#issue-399941409
hypothesis/h#5497https://github.com/hypothesis/h/pull/5497
https://github.com/untitaker
untitakerhttps://github.com/untitaker
on Jan 16, 2019https://github.com/getsentry/sentry-python/issues/237#issuecomment-454890780
#236https://github.com/getsentry/sentry-python/pull/236
untitakerhttps://github.com/untitaker
bughttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22bug%22
on Jan 16, 2019https://github.com/getsentry/sentry-python/issues/237#event-2078220785
https://github.com/seanh
seanhhttps://github.com/seanh
on Jan 16, 2019https://github.com/getsentry/sentry-python/issues/237#issuecomment-454892455
https://github.com/untitaker
untitakerhttps://github.com/untitaker
on Jan 23, 2019https://github.com/getsentry/sentry-python/issues/237#issuecomment-456766526
untitakerhttps://github.com/untitaker
completedhttps://github.com/getsentry/sentry-python/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jan 23, 2019https://github.com/getsentry/sentry-python/issues/237#event-2091367795
stephanie-andersonhttps://github.com/stephanie-anderson
Type: Bughttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Type%3A%20Bug%22
on Nov 21, 2024https://github.com/getsentry/sentry-python/issues/237#event-15380740160
Bughttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Bug%22
on Aug 13, 2025https://github.com/getsentry/sentry-python/issues/237#event-19125105234
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-python/issues/237
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-python/issues/237
Bughttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.