Skip to content

Commit f0d03b3

Browse files
committed
Fix reliability issue with current_app
1 parent cf9b3dc commit f0d03b3

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

api/src/api/services/engagement_service.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""Service for engagement management."""
22

3+
import os
34
from datetime import datetime, timezone
45
from http import HTTPStatus
56
from typing import Mapping, Optional, Sequence, Union
67

78
from sqlalchemy.exc import SQLAlchemyError
89
from sqlalchemy.orm import selectinload
9-
from flask import current_app
10+
from flask import current_app, has_app_context
1011
from flask_restx import abort
1112
from marshmallow import ValidationError
1213

@@ -549,7 +550,13 @@ def delete(cls, engagement_id: int):
549550
one_of_roles = (Role.SUPER_ADMIN.value, Role.UNPUBLISH_ENGAGEMENT.value)
550551
authorization.check_auth(one_of_roles=one_of_roles)
551552

552-
current_env = current_app.config['ENVIRONMENT']
553+
current_env = (
554+
(current_app.config.get('ENVIRONMENT') if has_app_context() else '')
555+
or os.getenv('ENVIRONMENT')
556+
or os.getenv('DEPLOYMENT_ENV')
557+
or os.getenv('FLASK_ENV', 'development')
558+
).strip().lower()
559+
553560
if current_env in ('prod', 'production'):
554561
abort(HTTPStatus.FORBIDDEN, 'Cannot delete an engagement in production environment')
555562

0 commit comments

Comments
 (0)