Skip to content

Commit

Permalink
Updated Flask to version 3
Browse files Browse the repository at this point in the history
  • Loading branch information
meta-paul committed Jul 2, 2024
1 parent fbc55c8 commit 101edc5
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 117 deletions.
6 changes: 2 additions & 4 deletions mephisto/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def metrics_cli(args):
def review_app(
info: ScriptInfo,
host: Optional[str],
port: Optional[str],
port: Optional[int],
debug: bool = False,
force_rebuild: bool = False,
skip_build: bool = False,
Expand All @@ -384,7 +384,6 @@ def review_app(
"""
from flask.cli import show_server_banner
from flask.helpers import get_debug_flag
from flask.helpers import get_env
from mephisto.review_app.server import create_app
from werkzeug.serving import run_simple

Expand Down Expand Up @@ -435,8 +434,7 @@ def review_app(
debugger = debug

# Show Flask banner
eager_loading = not reload
show_server_banner(get_env(), debug, info.app_import_path, eager_loading)
show_server_banner(debug, info.app_import_path)

# Init Flask App
app = create_app(debug=debug)
Expand Down
15 changes: 8 additions & 7 deletions mephisto/review_app/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Tuple

from flask import Flask
from flask import jsonify
from flask_cors import CORS
from werkzeug import Response
from werkzeug.exceptions import HTTPException as WerkzeugHTTPException
Expand Down Expand Up @@ -82,26 +83,26 @@ def handle_flask_exception(e: WerkzeugHTTPException) -> Response:
return response

@app.errorhandler(Exception)
def handle_not_flask_exception(e: Exception) -> Tuple[dict, int]:
def handle_not_flask_exception(e: Exception) -> Tuple[Response, int]:
# Not to handle Flask exceptions here, pass it further to catch in `handle_flask_exception`
if isinstance(e, WerkzeugHTTPException):
return e

elif isinstance(e, ProlificException):
logger.exception("Prolific error")
return {
return jsonify({
"error": e.message,
}, status.HTTP_400_BAD_REQUEST
}), status.HTTP_400_BAD_REQUEST

elif isinstance(e, EntryDoesNotExistException):
return {
return jsonify({
"error": "Not found",
}, status.HTTP_404_NOT_FOUND
}), status.HTTP_404_NOT_FOUND

# Other uncaught exceptions
logger.error("".join(traceback.format_tb(e.__traceback__)))
return {
return jsonify({
"error": f"Server error: {e}",
}, status.HTTP_500_INTERNAL_SERVER_ERROR
}), status.HTTP_500_INTERNAL_SERVER_ERROR

return app
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os

from flask import Response
from flask import send_file
from flask.views import MethodView
from werkzeug.exceptions import NotFound
Expand All @@ -15,7 +16,7 @@


class TaskExportResultsJsonView(MethodView):
def get(self, task_id: str = None, n_units: int = None) -> dict:
def get(self, task_id: str = None, n_units: int = None) -> Response:
"""Get result data file in JSON format"""
results_dir = get_results_dir()
results_file_path = get_result_file_path(results_dir, task_id, n_units)
Expand All @@ -26,5 +27,5 @@ def get(self, task_id: str = None, n_units: int = None) -> dict:
return send_file(
results_file_path,
as_attachment=True,
attachment_filename=f"task-{task_id}-results.json",
download_name=f"task-{task_id}-results.json",
)
194 changes: 101 additions & 93 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ hydra-core = "^1.2.0"
tqdm = "^4.50.2"
websockets = "^10.1"
pyyaml = ">=5.4,<7.0"
markupsafe = "2.0.1"
markupsafe = "2.1.5"

# worker_addons
detoxify = { version = "^0.5.0", optional = true }
Expand All @@ -63,7 +63,7 @@ botocore = { version = "^1.20.95", optional = false }
xmltodict = { version = ">=0.12,<0.14", optional = false }

# cli
click = { version = "^7.0", optional = false }
click = { version = "^8.1.7", optional = false }
click_default_group = { version = "^1.2", optional = false }
tabulate = { version = ">=0.8.7,<0.10.0", optional = false }
rich = { version = "^12.5.1", optional = false }
Expand All @@ -73,10 +73,10 @@ rich-click = { version = "^1.5.1", optional = false }
prometheus-client = { version = "^0.13.1", optional = false }

# flask_architect
flask = { version = "^1.1", optional = false }
flask = { version = "^3.0.3", optional = false }
flask-cors = { version = "^4.0.0", optional = false }
gevent-websocket = { version = "^0.10.1", optional = false }
werkzeug = { version = "^1.0.1", optional = false }
werkzeug = { version = "^3.0.3", optional = false }

# mock_architect
tornado = { version = "^6.0", optional = false }
Expand Down
2 changes: 1 addition & 1 deletion test/review_app/server/api/test_grant_workers_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_grant_no_unit_ids_error(self, *args, **kwargs):
qualification_id=qualification_id,
worker_id=worker_id,
)
response = self.client.post(url)
response = self.client.post(url, json={})
result = response.json

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
2 changes: 1 addition & 1 deletion test/review_app/server/api/test_qualifications_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_qualification_create_success(self, *args, **kwargs):
def test_qualification_create_no_passed_name_error(self, *args, **kwargs):
with self.app_context:
url = url_for("qualifications")
response = self.client.post(url)
response = self.client.post(url, json={})
result = response.json

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
2 changes: 1 addition & 1 deletion test/review_app/server/api/test_revoke_workers_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_grant_no_unit_ids_error(self, *args, **kwargs):
qualification_id=qualification_id,
worker_id=worker_id,
)
response = self.client.post(url)
response = self.client.post(url, json={})
result = response.json

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
2 changes: 1 addition & 1 deletion test/review_app/server/api/test_units_approve_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestUnitsApproveView(BaseTestApiViewCase):
def test_units_approve_no_unit_ids_passed_error(self, *args, **kwargs):
with self.app_context:
url = url_for("units_approve")
response = self.client.post(url)
response = self.client.post(url, json={})
result = response.json

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
2 changes: 1 addition & 1 deletion test/review_app/server/api/test_units_reject_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestUnitsRejectView(BaseTestApiViewCase):
def test_units_reject_no_unit_ids_passed_error(self, *args, **kwargs):
with self.app_context:
url = url_for("units_reject")
response = self.client.post(url)
response = self.client.post(url, json={})
result = response.json

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
2 changes: 1 addition & 1 deletion test/review_app/server/api/test_units_soft_reject_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestUnitsSoftRejectView(BaseTestApiViewCase):
def test_units_soft_reject_no_unit_ids_passed_error(self, *args, **kwargs):
with self.app_context:
url = url_for("units_soft_reject")
response = self.client.post(url)
response = self.client.post(url, json={})
result = response.json

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
2 changes: 1 addition & 1 deletion test/review_app/server/api/test_worker_block_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_worker_block_no_review_note_passed_error(self, *args, **kwargs):

with self.app_context:
url = url_for("worker_block", worker_id=worker_id)
response = self.client.post(url)
response = self.client.post(url, json={})
result = response.json

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down

0 comments on commit 101edc5

Please sign in to comment.