Skip to content

Commit b8522a8

Browse files
YuriZmytrakovYuri Zmytrakov
authored andcommitted
Merge branch 'main' into CAT-1413
2 parents dc2e961 + 5723bba commit b8522a8

File tree

7 files changed

+49
-6
lines changed

7 files changed

+49
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010

1111
### Added
1212

13+
- Added the `ENV_MAX_LIMIT` environment variable to SFEOS, allowing overriding of the `MAX_LIMIT`, which controls the `?limit` parameter for returned items and STAC collections. [#434](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/434)
14+
- Updated the `format_datetime_range` function to support milliseconds. [#423](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/423)
15+
1316
### Changed
1417

1518
- Changed assets serialization to prevent mapping explosion while allowing asset inforamtion to be indexed. [#341](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/341)
19+
- Blocked the /collections/{collection_id}/bulk_items endpoint when environmental variable ENABLE_DATETIME_INDEX_FILTERING is set to true. [#438](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/438)
1620

1721
### Fixed
1822

@@ -22,7 +26,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2226

2327
- Added `id` field as secondary sort to sort config to ensure unique pagination tokens. [#421](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/421)
2428
- Added default environment variable `STAC_ITEM_LIMIT` to SFEOS for result limiting of returned items and STAC collections [#419](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/419)
25-
- Updated the `format_datetime_range` function to support milliseconds. [#423](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/423)
2629

2730
### Changed
2831

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ You can customize additional settings in your `.env` file:
228228
| `DATABASE_REFRESH` | Controls whether database operations refresh the index immediately after changes. If set to `true`, changes will be immediately searchable. If set to `false`, changes may not be immediately visible but can improve performance for bulk operations. If set to `wait_for`, changes will wait for the next refresh cycle to become visible. | `false` | Optional |
229229
| `ENABLE_TRANSACTIONS_EXTENSIONS` | Enables or disables the Transactions and Bulk Transactions API extensions. If set to `false`, the POST `/collections` route and related transaction endpoints (including bulk transaction operations) will be unavailable in the API. This is useful for deployments where mutating the catalog via the API should be prevented. | `true` | Optional |
230230
| `STAC_ITEM_LIMIT` | Sets the environment variable for result limiting to SFEOS for the number of returned items and STAC collections. | `10` | Optional |
231+
| `ENV_MAX_LIMIT` | Configures the environment variable in SFEOS to override the default `MAX_LIMIT`, which controls the limit parameter for returned items and STAC collections. | `10,000` | Optional |
231232

232233
> [!NOTE]
233234
> The variables `ES_HOST`, `ES_PORT`, `ES_USE_SSL`, `ES_VERIFY_CERTS` and `ES_TIMEOUT` apply to both Elasticsearch and OpenSearch backends, so there is no need to rename the key names to `OS_` even if you're using OpenSearch.

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,13 @@ def bulk_item_insert(
965965
A string indicating the number of items successfully added.
966966
"""
967967
request = kwargs.get("request")
968+
969+
if os.getenv("ENABLE_DATETIME_INDEX_FILTERING"):
970+
raise HTTPException(
971+
status_code=400,
972+
detail="The /collections/{collection_id}/bulk_items endpoint is invalid when ENABLE_DATETIME_INDEX_FILTERING is set to true. Try using the /collections/{collection_id}/items endpoint.",
973+
)
974+
968975
if request:
969976
base_url = str(request.base_url)
970977
else:

stac_fastapi/core/stac_fastapi/core/utilities.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010

1111
from stac_fastapi.types.stac import Item
1212

13-
MAX_LIMIT = 10000
13+
14+
def get_max_limit():
15+
"""
16+
Retrieve a MAX_LIMIT value from an environment variable.
17+
18+
Returns:
19+
int: The int value parsed from the environment variable.
20+
"""
21+
return int(os.getenv("ENV_MAX_LIMIT", 10000))
1422

1523

1624
def get_bool_env(name: str, default: Union[bool, str] = False) -> bool:

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
1919
from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer
20-
from stac_fastapi.core.utilities import MAX_LIMIT, bbox2polygon
20+
from stac_fastapi.core.utilities import bbox2polygon, get_max_limit
2121
from stac_fastapi.elasticsearch.config import AsyncElasticsearchSettings
2222
from stac_fastapi.elasticsearch.config import (
2323
ElasticsearchSettings as SyncElasticsearchSettings,
@@ -543,7 +543,7 @@ async def execute_search(
543543
index_param = ITEM_INDICES
544544
query = add_collections_to_body(collection_ids, query)
545545

546-
max_result_window = MAX_LIMIT
546+
max_result_window = get_max_limit()
547547

548548
size_limit = min(limit + 1, max_result_window)
549549

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
1717
from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer
18-
from stac_fastapi.core.utilities import MAX_LIMIT, bbox2polygon, get_bool_env
18+
from stac_fastapi.core.utilities import bbox2polygon, get_bool_env, get_max_limit
1919
from stac_fastapi.extensions.core.transaction.request import (
2020
PartialCollection,
2121
PartialItem,
@@ -575,7 +575,7 @@ async def execute_search(
575575

576576
search_body["sort"] = sort if sort else DEFAULT_SORT
577577

578-
max_result_window = MAX_LIMIT
578+
max_result_window = get_max_limit()
579579

580580
size_limit = min(limit + 1, max_result_window)
581581

stac_fastapi/tests/api/test_api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,3 +1540,27 @@ async def test_collection_items_limit_env_variable(
15401540
assert resp.status_code == 200
15411541
resp_json = resp.json()
15421542
assert int(limit) == len(resp_json["features"])
1543+
1544+
1545+
@pytest.mark.asyncio
1546+
async def test_search_max_item_limit(
1547+
app_client, load_test_data, txn_client, monkeypatch
1548+
):
1549+
limit = "10"
1550+
monkeypatch.setenv("ENV_MAX_LIMIT", limit)
1551+
1552+
test_collection = load_test_data("test_collection.json")
1553+
await create_collection(txn_client, test_collection)
1554+
1555+
item = load_test_data("test_item.json")
1556+
1557+
for i in range(20):
1558+
test_item = item.copy()
1559+
test_item["id"] = f"test-item-collection-{i}"
1560+
await create_item(txn_client, test_item)
1561+
1562+
resp = await app_client.get("/search", params={"limit": 20})
1563+
1564+
assert resp.status_code == 200
1565+
resp_json = resp.json()
1566+
assert int(limit) == len(resp_json["features"])

0 commit comments

Comments
 (0)