{"record":{"id":"3e48cee98e44bd8d","repo":"theonedev/onedev","slug":"count-should-not-be-greater-than-3e48ce","errorCode":null,"errorMessage":"Count should not be greater than ","messagePattern":"Count should not be greater than ","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java","lineNumber":91,"sourceCode":"\t@Api(order=100)\n\t@Path(\"/{workspaceId}\")\n\t@GET\n\tpublic Workspace getWorkspace(@PathParam(\"workspaceId\") Long workspaceId) {\n\t\tWorkspace workspace = workspaceService.load(workspaceId);\n\t\tif (!SecurityUtils.canCreateWorkspaces(workspace.getProject()))\n\t\t\tthrow new UnauthorizedException();\n\t\treturn workspace;\n\t}\n\n\t@Api(order=200)\n\t@GET\n\tpublic List<Workspace> queryWorkspaces(\n\t\t\t@QueryParam(\"query\") @Api(description=\"Syntax of this query is the same as in <a href='/~workspaces'>workspaces page</a>\", example=\"active\") String query,\n\t\t\t@QueryParam(\"offset\") @Api(example=\"0\") int offset,\n\t\t\t@QueryParam(\"count\") @Api(example=\"100\") int count) {\n\t\tvar subject = SecurityUtils.getSubject();\n\t\tif (!SecurityUtils.isAdministrator(subject) && count > RestConstants.MAX_PAGE_SIZE)\n\t\t\tthrow new NotAcceptableException(\"Count should not be greater than \" + RestConstants.MAX_PAGE_SIZE);\n\n\t\tvar parsedQuery = WorkspaceQuery.parse(null, query, true);\n\n\t\treturn workspaceService.query(subject, null, parsedQuery, offset, count);\n\t}\n\n\t@Api(order=300, description=\"Create new workspace\")\n\t@POST\n\tpublic Long createWorkspace(@NotNull @Valid WorkspaceCreateData data) {\n\t\tvar subject = SecurityUtils.getSubject();\n\t\tvar user = SecurityUtils.getUser(subject);\n\t\tif (user == null)\n\t\t\tthrow new UnauthorizedException();\n\n\t\tProject project = projectService.load(data.getProjectId());\n\t\tif (!SecurityUtils.canCreateWorkspaces(subject, project))\n\t\t\tthrow new UnauthorizedException();\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java#L73-L109","documentation":"WorkspaceResource.queryWorkspaces enforces a maximum page size (RestConstants.MAX_PAGE_SIZE) for non-administrator subjects. Requesting more workspaces per page than the limit throws NotAcceptableException with the max value in the message. This protects the server from expensive unbounded queries by ordinary users.","triggerScenarios":"GET /workspaces?count=N with N greater than RestConstants.MAX_PAGE_SIZE while authenticated as a non-admin user.","commonSituations":"Client scripts hardcoding a large count (e.g. 10000) to 'fetch everything'; pagination code copied from an admin-only script.","solutions":["Reduce the count parameter to RestConstants.MAX_PAGE_SIZE or less","Paginate with offset/count loops until fewer results than the page size are returned","Authenticate as an administrator if a larger single page is genuinely required"],"exampleFix":"// before\nlist = get(\"/workspaces?offset=0&count=10000\");\n// after\ndo { list = get(\"/workspaces?offset=\" + offset + \"&count=100\"); offset += list.size(); } while (list.size() == 100);","handlingStrategy":"validation","validationCode":"if (!isAdmin && count > MAX_PAGE_SIZE) count = MAX_PAGE_SIZE;","typeGuard":null,"tryCatchPattern":"try { queryWorkspaces(q, offset, count); } catch (NotAcceptableException e) { log.warn(\"page size too large, retrying with {}\"); queryWorkspaces(q, offset, MAX_PAGE_SIZE); }","preventionTips":["Clamp count to the documented MAX_PAGE_SIZE","Implement offset-based pagination instead of huge pages","Query as admin only when a full snapshot is unavoidable"],"tags":["rest-api","pagination","page-size"],"backgroundTag":"invalid-query-parameter","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}