From 7a546072190765e8514b0bf87b8556a74109554f Mon Sep 17 00:00:00 2001 From: hj24 Date: Tue, 14 Oct 2025 13:33:04 +0800 Subject: [PATCH] fix: raise error for unexpected account --- api/services/workflow_app_service.py | 8 +--- .../services/test_workflow_app_service.py | 44 +++++++------------ 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/api/services/workflow_app_service.py b/api/services/workflow_app_service.py index 24bff5881d..23dd436675 100644 --- a/api/services/workflow_app_service.py +++ b/api/services/workflow_app_service.py @@ -88,13 +88,7 @@ class WorkflowAppService: if created_by_account: account = session.scalar(select(Account).where(Account.email == created_by_account)) if not account: - return { - "page": page, - "limit": limit, - "total": 0, - "has_more": False, - "data": [], - } + raise ValueError(f"Account not found: {created_by_account}") stmt = stmt.join( Account, diff --git a/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py b/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py index 9e0510a0f7..431f9c02de 100644 --- a/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py +++ b/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py @@ -807,26 +807,13 @@ class TestWorkflowAppService: ) assert result_with_new_email["total"] == 3 assert all(log.created_by_role == CreatorUserRole.ACCOUNT for log in result_with_new_email["data"]) - - # Old email unbound, is expected to be 0 - result_with_old_email = service.get_paginate_workflow_app_logs( - session=db_session_with_containers, - app_model=app, - created_by_account=original_email, - page=1, - limit=20 - ) - assert result_with_old_email["total"] == 0 - # Result with unknown email, is expected to be 0 - result_with_unknown_email = service.get_paginate_workflow_app_logs( - session=db_session_with_containers, - app_model=app, - created_by_account="unknown@example.com", - page=1, - limit=20 - ) - assert result_with_unknown_email["total"] == 0 + # Old email unbound, is unexpected input, should raise ValueError + with pytest.raises(ValueError) as exc_info: + service.get_paginate_workflow_app_logs( + session=db_session_with_containers, app_model=app, created_by_account=original_email, page=1, limit=20 + ) + assert "Account not found" in str(exc_info.value) account.email = original_email db_session_with_containers.commit() @@ -841,15 +828,16 @@ class TestWorkflowAppService: ) assert result_no_session["total"] == 0 - # Test filtering by non-existent account email - result_no_account = service.get_paginate_workflow_app_logs( - session=db_session_with_containers, - app_model=app, - created_by_account="nonexistent@example.com", - page=1, - limit=20, - ) - assert result_no_account["total"] == 0 + # Test filtering by non-existent account email, is unexpected input, should raise ValueError + with pytest.raises(ValueError) as exc_info: + service.get_paginate_workflow_app_logs( + session=db_session_with_containers, + app_model=app, + created_by_account="nonexistent@example.com", + page=1, + limit=20, + ) + assert "Account not found" in str(exc_info.value) def test_get_paginate_workflow_app_logs_with_uuid_keyword_search( self, db_session_with_containers, mock_external_service_dependencies