AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(platform/marketplace): a long or blank search no longer breaks the search page (#15587)
Reinier van der Leere4d9e5c4f2fe
diff --git a/autogpt_platform/backend/backend/api/features/store/db.py b/autogpt_platform/backend/backend/api/features/store/db.pyindex 071efb447f..b913d1ded3 100644--- a/autogpt_platform/backend/backend/api/features/store/db.py+++ b/autogpt_platform/backend/backend/api/features/store/db.py@@ -40,6 +40,9 @@ settings = Settings()DEFAULT_ADMIN_NAME = "AutoGPT Admin"DEFAULT_ADMIN_EMAIL = "[email protected]"+# Creator search reads only this much of a query, which bounds its ILIKE pattern.+MAX_CREATOR_SEARCH_QUERY_LENGTH = 100+class StoreAgentsSortOptions(Enum):RATING = "rating"@@ -513,12 +516,8 @@ async def get_store_creators(where["is_featured"] = featured# Add search filter if provided, using parameterized queries- if search_query:- # Sanitize and validate search query by escaping special characters- sanitized_query = search_query.strip()- if not sanitized_query or len(sanitized_query) > 100: # Reasonable length limit- raise DatabaseError("Invalid search query")-+ sanitized_query = (search_query or "").strip()[:MAX_CREATOR_SEARCH_QUERY_LENGTH]+ if sanitized_query:# Escape special SQL characterssanitized_query = (sanitized_query.replace("\\", "\\\\")diff --git a/autogpt_platform/backend/backend/api/features/store/db_test.py b/autogpt_platform/backend/backend/api/features/store/db_test.pyindex e5a4c98b1a..3767caed55 100644--- a/autogpt_platform/backend/backend/api/features/store/db_test.py+++ b/autogpt_platform/backend/backend/api/features/store/db_test.py@@ -591,6 +591,27 @@ async def test_get_store_creators_only_returns_approved(mocker):assert count_kwargs["where"]["num_agents"] == {"gt": 0}[email protected](loop_scope="session")+ "search_query, searched_for",+ [("a" * 300, {"a" * 100}), (" ", set())],+ ids=["over-long query searches its first 100 characters", "blank query"],+)+async def test_get_store_creators_accepts_long_and_blank_queries(+ mocker, search_query, searched_for+):+ mock_creator = mocker.patch("prisma.models.Creator.prisma")+ mock_creator.return_value.find_many = AsyncMock(return_value=[])+ mock_creator.return_value.count = AsyncMock(return_value=0)++ await db.get_store_creators(search_query=search_query)++ where = mock_creator.return_value.find_many.call_args.kwargs["where"]+ assert {+ match["contains"] for field in where.get("OR", []) for match in field.values()+ } == searched_for++@pytest.mark.asyncio(loop_scope="session")async def test_get_submission_stats_maps_row_to_pydantic(mocker):"""The single FILTER aggregate query result maps cleanly into SubmissionStats."""diff --git a/autogpt_platform/backend/backend/api/features/store/routes.py b/autogpt_platform/backend/backend/api/features/store/routes.pyindex 1ffdf1cd06..a2d09264ab 100644--- a/autogpt_platform/backend/backend/api/features/store/routes.py+++ b/autogpt_platform/backend/backend/api/features/store/routes.py@@ -326,7 +326,7 @@ async def get_creators(),sorted_by: store_db.StoreCreatorsSortOptions | None = None,page: int = Query(ge=1, default=1),- page_size: int = Query(ge=1, default=20),+ page_size: int = Query(ge=1, le=100, default=20),) -> store_model.CreatorsResponse:"""List or search marketplace creators"""creators = await store_cache._get_cached_store_creators(diff --git a/autogpt_platform/backend/backend/api/features/store/routes_test.py b/autogpt_platform/backend/backend/api/features/store/routes_test.pyindex 5cd1ae55f7..e55c130572 100644--- a/autogpt_platform/backend/backend/api/features/store/routes_test.py+++ b/autogpt_platform/backend/backend/api/features/store/routes_test.py@@ -508,6 +508,8 @@ def test_get_creators_pagination(def test_get_creators_malformed_request(mocker: pytest_mock.MockFixture):+ mock_db_call = mocker.patch("backend.api.features.store.db.get_store_creators")+# Test with invalid page numberresponse = client.get("/creators?page=-1")assert response.status_code == 422@@ -515,13 +517,13 @@ def test_get_creators_malformed_request(mocker: pytest_mock.MockFixture):# Test with invalid page sizeresponse = client.get("/creators?page_size=0")assert response.status_code == 422+ response = client.get("/creators?page_size=101")+ assert response.status_code == 422# Test with non-numeric valuesresponse = client.get("/creators?page=abc&page_size=def")assert response.status_code == 422- # Verify no DB calls were made- mock_db_call = mocker.patch("backend.api.features.store.db.get_store_creators")mock_db_call.assert_not_called()diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.jsonindex 29d5abf70b..d8a116d932 100644--- a/autogpt_platform/frontend/src/app/api/openapi.json+++ b/autogpt_platform/frontend/src/app/api/openapi.json@@ -16473,6 +16473,7 @@"required": false,"schema": {"type": "integer",+ "maximum": 100,"minimum": 1,"default": 20,"title": "Page Size"