Bump utils to bring in fix for optional placeholder bug

See https://github.com/alphagov/notifications-utils/pull/878 for
details.

Changes we had to make for our app and tests to work correctly
after the dependency updates:

1. Update emergency alerts polygons test because we changed
how exact we are with locations of the points on the map.

2. Use Flask's g object to set additional request attributes

So far we have been storing them in _request_ctx_stack which is
an innard for Flask's request context.

Because of major update to Werkzeug dependency, which Flask relies
on, the way we were using it stopped working, so we had a new
way to set those values.
The way we set those values now, by using g object, seems to also
be favoured in Flask documentation:
https://flask.palletsprojects.com/en/1.1.x/reqcontext/#how-the-context-works
This commit is contained in:
Pea Tyczynska
2021-07-07 17:35:15 +01:00
parent 273d14fbe4
commit 9e8682ac29
5 changed files with 22 additions and 23 deletions

View File

@@ -7,7 +7,6 @@ from time import monotonic
from celery import current_task
from flask import (
_request_ctx_stack,
current_app,
g,
has_request_context,
@@ -69,8 +68,8 @@ metrics = GDSMetrics()
notification_provider_clients = NotificationProviderClients()
api_user = LocalProxy(lambda: _request_ctx_stack.top.api_user)
authenticated_service = LocalProxy(lambda: _request_ctx_stack.top.authenticated_service)
api_user = LocalProxy(lambda: g.api_user)
authenticated_service = LocalProxy(lambda: g.authenticated_service)
CONCURRENT_REQUESTS = Gauge(
'concurrent_web_request_count',

View File

@@ -1,6 +1,6 @@
import uuid
from flask import _request_ctx_stack, current_app, g, request
from flask import current_app, g, request
from gds_metrics import Histogram
from notifications_python_client.authentication import (
decode_jwt_token,
@@ -140,8 +140,8 @@ def requires_auth():
raise AuthError("Invalid token: API key revoked", 403, service_id=service.id, api_key_id=api_key.id)
g.service_id = service.id
_request_ctx_stack.top.authenticated_service = service
_request_ctx_stack.top.api_user = api_key
g.api_user = api_key
g.authenticated_service = service
current_app.logger.info('API authorised for service {} with api key {}, using issuer {} for URL: {}'.format(
service.id,