From ce3784d39581c0917d8ab99907bc52a2473f7a2d Mon Sep 17 00:00:00 2001 From: Jake Herrmann Date: Mon, 4 Nov 2024 11:51:26 -0900 Subject: [PATCH 1/6] bump flask --- requirements-apps-api.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-apps-api.txt b/requirements-apps-api.txt index ce688299c..43a36f107 100644 --- a/requirements-apps-api.txt +++ b/requirements-apps-api.txt @@ -1,4 +1,4 @@ -flask==2.2.5 +Flask==3.0.3 Flask-Cors==5.0.0 jsonschema==4.23.0 openapi-core==0.19.4 From c8bc5fb18729464133a72657fba48bcfa522f789 Mon Sep 17 00:00:00 2001 From: Jake Herrmann Date: Thu, 7 Nov 2024 11:46:36 -0900 Subject: [PATCH 2/6] do not use Decimal in expected API responses for tests --- tests/test_api/test_patch_user.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_api/test_patch_user.py b/tests/test_api/test_patch_user.py index a3086a63d..7185d77e8 100644 --- a/tests/test_api/test_patch_user.py +++ b/tests/test_api/test_patch_user.py @@ -18,7 +18,7 @@ def test_patch_new_user(client, tables): assert response.json == { 'user_id': 'foo', 'application_status': APPLICATION_PENDING, - 'remaining_credits': Decimal(0), + 'remaining_credits': 0, 'job_names': [], 'use_case': 'I want data.', } @@ -45,7 +45,7 @@ def test_patch_pending_user(client, tables): assert response.status_code == HTTPStatus.OK assert response.json == { 'user_id': 'foo', - 'remaining_credits': Decimal(0), + 'remaining_credits': 0, 'application_status': APPLICATION_PENDING, 'use_case': 'New use case.', 'job_names': [], @@ -92,7 +92,7 @@ def test_patch_user_access_code(client, tables): assert response.json == { 'user_id': 'foo', 'application_status': APPLICATION_APPROVED, - 'remaining_credits': Decimal(25), + 'remaining_credits': 25, 'job_names': [], 'use_case': 'I want data.', 'access_code': '123', From b493e34b515c7ce76a15be3bfd6957cd953cefd7 Mon Sep 17 00:00:00 2001 From: Jake Herrmann Date: Thu, 7 Nov 2024 12:18:21 -0900 Subject: [PATCH 3/6] fix test failures caused by how Flask handles custom json encoders --- apps/api/src/hyp3_api/routes.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/api/src/hyp3_api/routes.py b/apps/api/src/hyp3_api/routes.py index e3c820d05..e0d69998f 100644 --- a/apps/api/src/hyp3_api/routes.py +++ b/apps/api/src/hyp3_api/routes.py @@ -6,6 +6,7 @@ import yaml from flask import abort, g, jsonify, make_response, redirect, render_template, request +from flask.json.provider import JSONProvider from flask_cors import CORS from openapi_core import OpenAPI from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator @@ -87,13 +88,24 @@ def default(self, o): if isinstance(o, datetime.date): return o.isoformat() + if isinstance(o, Decimal): if o == int(o): return int(o) return float(o) + + # Raises a TypeError json.JSONEncoder.default(self, o) +class CustomJSONProvider(JSONProvider): + def dumps(self, o): + return json.dumps(o, cls=CustomEncoder) + + def loads(self, s): + return json.loads(s) + + class ErrorHandler(FlaskOpenAPIErrorsHandler): def __init__(self): super().__init__() @@ -104,7 +116,7 @@ def __call__(self, errors): return handlers.problem_format(error['status'], error['title']) -app.json_encoder = CustomEncoder +app.json = CustomJSONProvider(app) openapi = FlaskOpenAPIViewDecorator( api_spec, From a9a9046291a350d097161b8c3f6f655a79d24067 Mon Sep 17 00:00:00 2001 From: Jake Herrmann Date: Thu, 7 Nov 2024 12:29:57 -0900 Subject: [PATCH 4/6] changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18de461ca..2d6c0b2de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [8.0.1] + +### Fixed +- Upgraded from `flask==2.2.5` to `Flask==3.0.3`. Fixes a bug in which Dependabot was not tracking Flask upgrades because we specified the dependency name as lowercase. +- We now specify our custom JSON encoder by subclassing `flask.json.provider.JSONProvider`. See + ## [8.0.0] ### Added From 258df86e29b1d683db9af528c437b3dcdd2a262e Mon Sep 17 00:00:00 2001 From: Jake Herrmann Date: Thu, 7 Nov 2024 12:33:44 -0900 Subject: [PATCH 5/6] tweak changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d6c0b2de..d17c7b004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [8.0.1] ### Fixed -- Upgraded from `flask==2.2.5` to `Flask==3.0.3`. Fixes a bug in which Dependabot was not tracking Flask upgrades because we specified the dependency name as lowercase. -- We now specify our custom JSON encoder by subclassing `flask.json.provider.JSONProvider`. See +- Upgrade from `flask==2.2.5` to `Flask==3.0.3`. Fixes a bug in which Dependabot was not tracking Flask upgrades because we specified the dependency name as lowercase. +- Specify our custom JSON encoder by subclassing `flask.json.provider.JSONProvider`. See ## [8.0.0] From 3c9161a12eb5a05625da474263c39348c73ca8dd Mon Sep 17 00:00:00 2001 From: Jake Herrmann Date: Thu, 7 Nov 2024 12:49:03 -0900 Subject: [PATCH 6/6] downgrade Flask to test dependabot --- requirements-apps-api.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements-apps-api.txt b/requirements-apps-api.txt index 43a36f107..469dde376 100644 --- a/requirements-apps-api.txt +++ b/requirements-apps-api.txt @@ -1,4 +1,5 @@ -Flask==3.0.3 +# TODO: verify that dependabot bumps to Flask 3.0.3 on Monday +Flask==3.0.2 Flask-Cors==5.0.0 jsonschema==4.23.0 openapi-core==0.19.4