@@ -170,6 +170,7 @@ def __init__(self, config: ClientConfig, api_version: str | None, cognite_client
170170 super ().__init__ (config , api_version , cognite_client )
171171 self ._AGGREGATE_LIMIT = 1000
172172 self ._SEARCH_LIMIT = 1000
173+ self .__dm_semaphore = get_global_data_modeling_semaphore ()
173174
174175 self ._warn_on_alpha_debug_settings = FeaturePreviewWarning (
175176 api_maturity = "alpha" ,
@@ -297,7 +298,7 @@ async def __call__(
297298 filter = filter .dump (camel_case_property = False ) if isinstance (filter , Filter ) else filter ,
298299 other_params = other_params ,
299300 headers = headers ,
300- semaphore = get_global_data_modeling_semaphore ( self ._config . project ) ,
301+ semaphore = self .__dm_semaphore ,
301302 ):
302303 yield item
303304 return
@@ -310,7 +311,7 @@ async def __call__(
310311 filter = filter .dump (camel_case_property = False ) if isinstance (filter , Filter ) else filter ,
311312 other_params = other_params ,
312313 headers = headers ,
313- semaphore = get_global_data_modeling_semaphore ( self ._config . project ) ,
314+ semaphore = self .__dm_semaphore ,
314315 ):
315316 yield list_cls ._load_raw_api_response ([raw ])
316317
@@ -634,7 +635,7 @@ def _load_raw_api_response(cls, responses: list[dict[str, Any]]) -> _NodeOrEdgeL
634635 identifiers = identifiers ,
635636 other_params = other_params ,
636637 settings_forcing_raw_response_loading = [f"{ include_typing = } " ] if include_typing else None ,
637- semaphore = get_global_data_modeling_semaphore ( self ._config . project ) ,
638+ semaphore = self .__dm_semaphore ,
638639 )
639640
640641 return InstancesResult [T_Node , T_Edge ](
@@ -722,7 +723,7 @@ async def delete(
722723 identifiers ,
723724 wrap_ids = True ,
724725 returns_items = True ,
725- semaphore = get_global_data_modeling_semaphore ( self ._config . project ) ,
726+ semaphore = self .__dm_semaphore ,
726727 ),
727728 )
728729 node_ids = [NodeId .load (item ) for item in deleted_instances if item ["instanceType" ] == "node" ]
@@ -788,7 +789,7 @@ async def inspect(
788789 response = await self ._post (
789790 self ._RESOURCE_PATH + "/inspect" ,
790791 json = {"items" : chunk .as_dicts (), "inspectionOperations" : inspect_operations },
791- semaphore = get_global_data_modeling_semaphore ( self ._config . project ) ,
792+ semaphore = self .__dm_semaphore ,
792793 )
793794 items .extend (unpack_items (response ))
794795
@@ -1067,7 +1068,7 @@ async def apply(
10671068 resource_cls = _NodeOrEdgeApplyResultAdapter , # type: ignore[type-var]
10681069 extra_body_fields = other_parameters ,
10691070 input_resource_cls = _NodeOrEdgeApplyAdapter , # type: ignore[arg-type]
1070- semaphore = get_global_data_modeling_semaphore ( self ._config . project ) ,
1071+ semaphore = self .__dm_semaphore ,
10711072 )
10721073 return InstancesApplyResult (
10731074 nodes = NodeApplyResultList ([item for item in res if isinstance (item , NodeApplyResult )]),
@@ -1257,11 +1258,7 @@ async def search(
12571258 raise ValueError ("nulls_first argument is not supported when sorting on instance search" )
12581259 body ["sort" ] = [self ._dump_instance_sort (s ) for s in sorts ]
12591260
1260- res = await self ._post (
1261- url_path = self ._RESOURCE_PATH + "/search" ,
1262- json = body ,
1263- semaphore = get_global_data_modeling_semaphore (self ._config .project ),
1264- )
1261+ res = await self ._post (url_path = self ._RESOURCE_PATH + "/search" , json = body , semaphore = self .__dm_semaphore )
12651262 result = res .json ()
12661263 return list_cls (
12671264 [resource_cls ._load (item ) for item in result ["items" ]], # type: ignore [misc]
@@ -1386,11 +1383,7 @@ async def aggregate(
13861383 if target_units :
13871384 body ["targetUnits" ] = [unit .dump (camel_case = True ) for unit in target_units ]
13881385
1389- res = await self ._post (
1390- url_path = self ._RESOURCE_PATH + "/aggregate" ,
1391- json = body ,
1392- semaphore = get_global_data_modeling_semaphore (self ._config .project ),
1393- )
1386+ res = await self ._post (url_path = self ._RESOURCE_PATH + "/aggregate" , json = body , semaphore = self .__dm_semaphore )
13941387 result_list = InstanceAggregationResultList ._load (res .json ()["items" ])
13951388 if group_by is not None :
13961389 return result_list
@@ -1499,11 +1492,7 @@ async def histogram(
14991492 if target_units :
15001493 body ["targetUnits" ] = [unit .dump (camel_case = True ) for unit in target_units ]
15011494
1502- res = await self ._post (
1503- url_path = self ._RESOURCE_PATH + "/aggregate" ,
1504- json = body ,
1505- semaphore = get_global_data_modeling_semaphore (self ._config .project ),
1506- )
1495+ res = await self ._post (url_path = self ._RESOURCE_PATH + "/aggregate" , json = body , semaphore = self .__dm_semaphore )
15071496 if is_singleton :
15081497 return HistogramValue .load (res .json ()["items" ][0 ]["aggregates" ][0 ])
15091498 else :
@@ -1662,10 +1651,7 @@ async def _query_or_sync(
16621651 headers = {"cdf-version" : f"{ self ._config .api_subversion } -alpha" }
16631652
16641653 response = await self ._post (
1665- url_path = self ._RESOURCE_PATH + f"/{ endpoint } " ,
1666- json = body ,
1667- headers = headers ,
1668- semaphore = get_global_data_modeling_semaphore (self ._config .project ),
1654+ url_path = self ._RESOURCE_PATH + f"/{ endpoint } " , json = body , headers = headers , semaphore = self .__dm_semaphore
16691655 )
16701656 json_payload = response .json ()
16711657 default_by_reference = query .instance_type_by_result_expression ()
@@ -1865,7 +1851,7 @@ async def list(
18651851 other_params = other_params ,
18661852 settings_forcing_raw_response_loading = settings_forcing_raw_response_loading ,
18671853 headers = headers ,
1868- semaphore = get_global_data_modeling_semaphore ( self ._config . project ) ,
1854+ semaphore = self .__dm_semaphore ,
18691855 ),
18701856 )
18711857
0 commit comments