From c72f7b8024fbf5ca187e403e38d57998d4bc383d Mon Sep 17 00:00:00 2001 From: Mark Moes Date: Wed, 20 Nov 2024 09:49:46 +0100 Subject: [PATCH] Add app_setting VALIDATE_OUT_OF_SYNC_SUBSCRIPTIONS + Bump nwa-stdlib 1.8.3 for ErrorType.BAD_REQUEST (#780) * Add option VALIDATE_OUT_OF_SYNC_SUBSCRIPTIONS to re-validate out-of-sync subscriptions in schedule Signed-off-by: Mark90 * Bump sentry-sdk to 2.18.0 to resolve strawberry-graphql ImportErrot Signed-off-by: Mark90 * Bump nwa-stdlib to 1.8.3 and register bad graphql input parameters as ErrorType.BAD_REQUEST This avoids masking useful error response Signed-off-by: Mark90 * Bump version to 2.9.0rc2 Signed-off-by: Mark90 --------- Signed-off-by: Mark90 --- .bumpversion.cfg | 2 +- orchestrator/__init__.py | 2 +- .../graphql/utils/create_resolver_error_handler.py | 4 ++-- orchestrator/schedules/validate_subscriptions.py | 10 +++++++--- orchestrator/settings.py | 1 + pyproject.toml | 4 ++-- test/unit_tests/graphql/test_processes.py | 2 +- test/unit_tests/graphql/test_subscriptions.py | 6 +++--- 8 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 36b8a5cef..58afb18b2 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.9.0rc1 +current_version = 2.9.0rc2 commit = False tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(rc(?P\d+))? diff --git a/orchestrator/__init__.py b/orchestrator/__init__.py index 564dda1d0..4e590f013 100644 --- a/orchestrator/__init__.py +++ b/orchestrator/__init__.py @@ -13,7 +13,7 @@ """This is the orchestrator workflow engine.""" -__version__ = "2.9.0rc1" +__version__ = "2.9.0rc2" from orchestrator.app import OrchestratorCore from orchestrator.settings import app_settings diff --git a/orchestrator/graphql/utils/create_resolver_error_handler.py b/orchestrator/graphql/utils/create_resolver_error_handler.py index 668201914..38c92f774 100644 --- a/orchestrator/graphql/utils/create_resolver_error_handler.py +++ b/orchestrator/graphql/utils/create_resolver_error_handler.py @@ -12,7 +12,7 @@ # limitations under the License. -from nwastdlib.graphql.extensions.error_handler_extension import register_error +from nwastdlib.graphql.extensions.error_handler_extension import ErrorType, register_error from orchestrator.db.filters import CallableErrorHandler from orchestrator.graphql.types import OrchestratorInfo @@ -25,6 +25,6 @@ def _format_context(context: dict) -> str: def create_resolver_error_handler(info: OrchestratorInfo) -> CallableErrorHandler: def handle_error(message: str, **context) -> None: # type: ignore - return register_error(" ".join([message, _format_context(context)]), info) + return register_error(" ".join([message, _format_context(context)]), info, error_type=ErrorType.BAD_REQUEST) return handle_error diff --git a/orchestrator/schedules/validate_subscriptions.py b/orchestrator/schedules/validate_subscriptions.py index 698c3f13a..cd7df149f 100644 --- a/orchestrator/schedules/validate_subscriptions.py +++ b/orchestrator/schedules/validate_subscriptions.py @@ -21,6 +21,7 @@ from orchestrator.schedules.scheduling import scheduler from orchestrator.services.processes import get_execution_context from orchestrator.services.subscriptions import TARGET_DEFAULT_USABLE_MAP, WF_USABLE_MAP +from orchestrator.settings import app_settings from orchestrator.targets import Target logger = structlog.get_logger(__name__) @@ -31,9 +32,12 @@ @scheduler(name="Subscriptions Validator", time_unit="day", at="00:10") def validate_subscriptions() -> None: - subscriptions = db.session.scalars( - select(SubscriptionTable).join(ProductTable).filter(SubscriptionTable.insync.is_(True)) - ) + if app_settings.VALIDATE_OUT_OF_SYNC_SUBSCRIPTIONS: + # Automatically re-validate out-of-sync subscriptions. This is not recommended for production. + select_query = select(SubscriptionTable).join(ProductTable) + else: + select_query = select(SubscriptionTable).join(ProductTable).filter(SubscriptionTable.insync.is_(True)) + subscriptions = db.session.scalars(select_query) for subscription in subscriptions: validation_workflow = None diff --git a/orchestrator/settings.py b/orchestrator/settings.py index 265420dd1..8dff0143d 100644 --- a/orchestrator/settings.py +++ b/orchestrator/settings.py @@ -81,6 +81,7 @@ class AppSettings(BaseSettings): ENABLE_GRAPHQL_DEPRECATION_CHECKER: bool = True ENABLE_GRAPHQL_PROFILING_EXTENSION: bool = False ENABLE_GRAPHQL_STATS_EXTENSION: bool = False + VALIDATE_OUT_OF_SYNC_SUBSCRIPTIONS: bool = False app_settings = AppSettings() diff --git a/pyproject.toml b/pyproject.toml index 47be1b047..0d4711e8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,13 +54,13 @@ dependencies = [ "pytz==2024.1", "redis==5.0.3", "schedule==1.1.0", - "sentry-sdk[fastapi]==2.17.0", + "sentry-sdk[fastapi]~=2.18.0", "SQLAlchemy==2.0.31", "SQLAlchemy-Utils==0.41.2", "structlog", "typer==0.12.5", "uvicorn[standard]~=0.32.0", - "nwa-stdlib~=1.8.0", + "nwa-stdlib~=1.8.3", "oauth2-lib~=2.3.0", "tabulate==0.9.0", "strawberry-graphql>=0.246.2", diff --git a/test/unit_tests/graphql/test_processes.py b/test/unit_tests/graphql/test_processes.py index e533a82ee..f90f3da09 100644 --- a/test/unit_tests/graphql/test_processes.py +++ b/test/unit_tests/graphql/test_processes.py @@ -414,7 +414,7 @@ def test_processes_filtering_with_invalid_filter( "'workflowName'])" ), "path": ["processes"], - "extensions": {"error_type": "internal_error"}, + "extensions": {"error_type": "bad_request"}, } ] assert pageinfo == { diff --git a/test/unit_tests/graphql/test_subscriptions.py b/test/unit_tests/graphql/test_subscriptions.py index 849d21908..59bf69e14 100644 --- a/test/unit_tests/graphql/test_subscriptions.py +++ b/test/unit_tests/graphql/test_subscriptions.py @@ -649,7 +649,7 @@ def test_subscriptions_sorting_invalid_field(test_client, product_type_1_subscri "'subscriptionId', 'tag'])" ), "path": ["subscriptions"], - "extensions": {"error_type": "internal_error"}, + "extensions": {"error_type": "bad_request"}, } ] @@ -668,7 +668,7 @@ def test_subscriptions_sorting_invalid_order(test_client, product_type_1_subscri assert not result["data"] assert "errors" in result - assert "Value 'test' does not exist in 'SortOrder'" in result["errors"][0]["message"] + assert "Internal Server Error" in result["errors"][0]["message"] @pytest.mark.parametrize( @@ -807,7 +807,7 @@ def test_subscriptions_filtering_with_invalid_filter( "'note', 'product', 'productId', 'startDate', 'status', 'subscriptionId', 'tag'])" ), "path": ["subscriptions"], - "extensions": {"error_type": "internal_error"}, + "extensions": {"error_type": "bad_request"}, } ] assert pageinfo == {