Skip to content

Flask Integration Notifier does not work outside request context #271

@sarartur

Description

@sarartur

What

👋 I am currently experiencing the following issue:

The notifier app.extensions['pybrake'] does not work outside request context due to this check:

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions