File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99from mp_api .client import __file__ as root_dir
1010
1111PMG_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
1718try :
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_"
Original file line number Diff line number Diff line change 1010from pydantic ._internal ._utils import lenient_issubclass
1111from pydantic .fields import FieldInfo
1212
13+ from mp_api .client .core .settings import MAPIClientSettings
14+
1315
1416def 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 :
You can’t perform that action at this time.
0 commit comments