mirror of
https://github.com/langgenius/dify.git
synced 2026-06-26 14:51:13 +08:00
fix(datasets): validate console dataset list pagination as >= 1
ConsoleDatasetListQuery accepted any integer page/limit, so a negative or zero value passed straight through to DatasetService.get_datasets and on to the DB pagination. The annotation list queries already guard this with Field(ge=1) (both console and service_api); apply the same bound to the console dataset list query for consistency. Add unit tests covering the defaults, a valid page/limit, and rejection of non-positive page and limit. From Claude Code. Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
This commit is contained in:
parent
762321751c
commit
4e99a98c23
@ -136,8 +136,8 @@ class IndexingEstimatePayload(BaseModel):
|
||||
|
||||
|
||||
class ConsoleDatasetListQuery(BaseModel):
|
||||
page: int = Field(default=1, description="Page number")
|
||||
limit: int = Field(default=20, description="Number of items per page")
|
||||
page: int = Field(default=1, ge=1, description="Page number")
|
||||
limit: int = Field(default=20, ge=1, description="Number of items per page")
|
||||
keyword: str | None = Field(default=None, description="Search keyword")
|
||||
include_all: bool = Field(default=False, description="Include all datasets")
|
||||
ids: list[str] = Field(default_factory=list, description="Filter by dataset IDs")
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from controllers.console.datasets.datasets import ConsoleDatasetListQuery
|
||||
|
||||
|
||||
def test_dataset_list_query_defaults() -> None:
|
||||
query = ConsoleDatasetListQuery()
|
||||
assert query.page == 1
|
||||
assert query.limit == 20
|
||||
|
||||
|
||||
def test_dataset_list_query_accepts_valid_pagination() -> None:
|
||||
query = ConsoleDatasetListQuery(page=3, limit=50)
|
||||
assert query.page == 3
|
||||
assert query.limit == 50
|
||||
|
||||
|
||||
def test_dataset_list_query_rejects_non_positive_page() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
ConsoleDatasetListQuery(page=0)
|
||||
with pytest.raises(ValidationError):
|
||||
ConsoleDatasetListQuery(page=-1)
|
||||
|
||||
|
||||
def test_dataset_list_query_rejects_non_positive_limit() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
ConsoleDatasetListQuery(limit=0)
|
||||
with pytest.raises(ValidationError):
|
||||
ConsoleDatasetListQuery(limit=-5)
|
||||
Loading…
Reference in New Issue
Block a user