Skip to content

Commit

Permalink
Add app_setting VALIDATE_OUT_OF_SYNC_SUBSCRIPTIONS + Bump nwa-stdlib …
Browse files Browse the repository at this point in the history
…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 <[email protected]>

* Bump sentry-sdk to 2.18.0 to resolve strawberry-graphql ImportErrot

Signed-off-by: Mark90 <[email protected]>

* 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 <[email protected]>

* Bump version to 2.9.0rc2

Signed-off-by: Mark90 <[email protected]>

---------

Signed-off-by: Mark90 <[email protected]>
  • Loading branch information
Mark90 authored Nov 20, 2024
1 parent 25225a3 commit c72f7b8
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.9.0rc1
current_version = 2.9.0rc2
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(rc(?P<build>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions orchestrator/graphql/utils/create_resolver_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
10 changes: 7 additions & 3 deletions orchestrator/schedules/validate_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions orchestrator/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/graphql/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == {
Expand Down
6 changes: 3 additions & 3 deletions test/unit_tests/graphql/test_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
]

Expand All @@ -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(
Expand Down Expand Up @@ -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 == {
Expand Down

0 comments on commit c72f7b8

Please sign in to comment.