Skip to content

Commit 0a1561a

Browse files
author
Jason Munro
authored
Update max values in settings (#875)
* Set max value for api client settings * Add upper bound on ID list queries * Linting * Spelling
1 parent 5351c9b commit 0a1561a

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

mp_api/client/core/settings.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
from mp_api.client import __file__ as root_dir
1010

1111
PMG_SETTINGS = _load_pmg_settings()
12-
_NUM_PARALLEL_REQUESTS = PMG_SETTINGS.get("MPRESTER_NUM_PARALLEL_REQUESTS", 8)
13-
_MAX_RETRIES = PMG_SETTINGS.get("MPRESTER_MAX_RETRIES", 3)
12+
_NUM_PARALLEL_REQUESTS = min(PMG_SETTINGS.get("MPRESTER_NUM_PARALLEL_REQUESTS", 8), 8)
13+
_MAX_RETRIES = min(PMG_SETTINGS.get("MPRESTER_MAX_RETRIES", 3), 3)
1414
_MUTE_PROGRESS_BAR = PMG_SETTINGS.get("MPRESTER_MUTE_PROGRESS_BARS", False)
1515
_MAX_HTTP_URL_LENGTH = PMG_SETTINGS.get("MPRESTER_MAX_HTTP_URL_LENGTH", 2000)
16+
_MAX_LIST_LENGTH = min(PMG_SETTINGS.get("MPRESTER_MAX_LIST_LENGTH", 40000), 40000)
1617

1718
try:
1819
CPU_COUNT = cpu_count()
@@ -82,5 +83,9 @@ class MAPIClientSettings(BaseSettings):
8283
"0.54.0", description="Minimum compatible version of emmet-core for the client."
8384
)
8485

86+
MAX_LIST_LENGTH: int = Field(
87+
_MAX_LIST_LENGTH, description="Maximum length of query parameter list"
88+
)
89+
8590
class Config:
8691
env_prefix = "MPRESTER_"

mp_api/client/core/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from pydantic._internal._utils import lenient_issubclass
1111
from pydantic.fields import FieldInfo
1212

13+
from mp_api.client.core.settings import MAPIClientSettings
14+
1315

1416
def validate_ids(id_list: list[str]):
1517
"""Function to validate material and task IDs.
@@ -23,6 +25,12 @@ def validate_ids(id_list: list[str]):
2325
Returns:
2426
id_list: Returns original ID list if everything is formatted correctly.
2527
"""
28+
if len(id_list) >= MAPIClientSettings().MAX_LIST_LENGTH:
29+
raise ValueError(
30+
"List of material/molecule IDs provided is too long. Consider removing the ID filter to automatically pull"
31+
" data for all IDs and filter locally."
32+
)
33+
2634
pattern = "(mp|mvc|mol|mpcule)-.*"
2735

2836
for entry in id_list:

0 commit comments

Comments
 (0)