kvesteri / postgresql-audit

Audit trigger for PostgreSQL
BSD 2-Clause "Simplified" License
126 stars 28 forks source link

Allow using activity_values in app scope #75

Closed tvuotila closed 1 year ago

tvuotila commented 1 year ago

The request scope is not available in scripts etc.

This removes current_app.test_request_context() from something like:

from flask import current_app
from postgresql_audit.flask import activity_values
with current_app.test_request_context(), activity_values(some='value'):
    ...

Previously, the activity_values(some='value') would do nothing if there was no request context.

I also refactored the code to remove has_request_context. That is safe as documented by flask.has_request_context documentation.

flask.g is bound to application context (documentation)

BREAKING CHANGE: activity_values is set in more cases than before. To be exact, the activity_values is also set when request context is not available, but the application context is.