-
Notifications
You must be signed in to change notification settings - Fork 15
Description
What
👋 I am currently experiencing the following issue:
The notifier app.extensions['pybrake']
does not work outside request context due to this check:
pybrake/src/pybrake/middleware/flask.py
Lines 34 to 35 in f506588
if request is None: | |
return notice |
Outside of request context flask returns <LocalProxy unbound>
which is a truthy value, so it tries to run the filter and raises RuntimeError: Working outside of request context.
Flask version: 3.1.1
Pybrake version: 1.10.1
Why
This is an issue if trying to then pass integration the same notifier with celery
via patch_celery(flask_app.extensions["pybrake"])
for example or if you want to use notifier outside of request context like in CLI command / task for example.
Current workaround
I am able to get this working by filtering out the filter before passing it to celery:
airbrake_notifier._filters = [
f for f in airbrake_notifier._filters if f.__name__ != 'request_filter'
]
But obviously accessing 'private' var _filters
is not ideal
Proposal
Would it be possible to add further handling to skip this filter if working outside of request context? Happy to submit a PR to the upstream. Thanks :)