Skip to content

Commit cad5e5c

Browse files
authored
Ensure limit 0 searches return 400 (#296)
* Ensure limit 0 searches return 400 * Update changelog
1 parent 3219b65 commit cad5e5c

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Fixed
1212

13+
* The minimum `limit` value for searches is now 1 ([#296](https://github.com/stac-utils/stac-fastapi/pull/296))
1314
* Links stored with Collections and Items (e.g. license links) are now returned with those STAC objects ([#282](https://github.com/stac-utils/stac-fastapi/pull/282))
1415

1516
## [2.2.0]

stac_fastapi/pgstac/stac_fastapi/pgstac/types/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class PgstacSearch(Search):
100100
token: Optional[str] = None
101101
datetime: Optional[str] = None
102102
sortby: Any
103-
limit: Optional[conint(ge=0, le=10000)] = 10
103+
limit: Optional[conint(gt=0, le=10000)] = 10
104104

105105
@root_validator(pre=True)
106106
def validate_query_fields(cls, values: Dict) -> Dict:

stac_fastapi/pgstac/tests/api/test_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ async def test_app_query_extension_limit_1(
8181
assert len(resp_json["features"]) == 1
8282

8383

84+
@pytest.mark.asyncio
85+
async def test_app_query_extension_limit_eq0(app_client):
86+
params = {"limit": 0}
87+
resp = await app_client.post("/search", json=params)
88+
assert resp.status_code == 400
89+
90+
8491
@pytest.mark.asyncio
8592
async def test_app_query_extension_limit_lt0(
8693
load_test_data, app_client, load_test_collection

stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/types/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class SQLAlchemySTACSearch(Search):
145145
# Override query extension with supported operators
146146
query: Optional[Dict[Queryables, Dict[Operator, Any]]]
147147
token: Optional[str] = None
148-
limit: Optional[conint(ge=0, le=10000)] = 10
148+
limit: Optional[conint(gt=0, le=10000)] = 10
149149

150150
@root_validator(pre=True)
151151
def validate_query_fields(cls, values: Dict) -> Dict:

stac_fastapi/sqlalchemy/tests/api/test_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ def test_app_query_extension_gte(load_test_data, app_client, postgres_transactio
102102
assert len(resp_json["features"]) == 1
103103

104104

105+
def test_app_query_extension_limit_eq0(app_client):
106+
params = {"limit": 0}
107+
resp = app_client.post("/search", json=params)
108+
assert resp.status_code == 400
109+
110+
105111
def test_app_query_extension_limit_lt0(
106112
load_test_data, app_client, postgres_transactions
107113
):

0 commit comments

Comments
 (0)