@@ -314,7 +314,9 @@ async def init(
314314
315315 return cls (** attrs )
316316
317- async def handle_pool (self , db : InfrahubDatabase , attribute : BaseAttribute , errors : list ) -> None :
317+ async def handle_pool (
318+ self , db : InfrahubDatabase , attribute : BaseAttribute , errors : list , allocate_resources : bool = True
319+ ) -> None :
318320 """Evaluate if a resource has been requested from a pool and apply the resource
319321
320322 This method only works on number pools, currently Integer is the only type that has the from_pool
@@ -325,7 +327,7 @@ async def handle_pool(self, db: InfrahubDatabase, attribute: BaseAttribute, erro
325327 attribute .from_pool = {"id" : attribute .schema .parameters .number_pool_id }
326328 attribute .is_default = False
327329
328- if not attribute .from_pool :
330+ if not attribute .from_pool or not allocate_resources :
329331 return
330332
331333 try :
@@ -485,7 +487,7 @@ async def handle_object_template(self, fields: dict, db: InfrahubDatabase, error
485487 elif relationship_peers := await relationship .get_peers (db = db ):
486488 fields [relationship_name ] = [{"id" : peer_id } for peer_id in relationship_peers ]
487489
488- async def _process_fields (self , fields : dict , db : InfrahubDatabase ) -> None :
490+ async def _process_fields (self , fields : dict , db : InfrahubDatabase , process_pools : bool = True ) -> None :
489491 errors = []
490492
491493 if "_source" in fields .keys ():
@@ -539,7 +541,7 @@ async def _process_fields(self, fields: dict, db: InfrahubDatabase) -> None:
539541 # Generate Attribute and Relationship and assign them
540542 # -------------------------------------------
541543 errors .extend (await self ._process_fields_relationships (fields = fields , db = db ))
542- errors .extend (await self ._process_fields_attributes (fields = fields , db = db ))
544+ errors .extend (await self ._process_fields_attributes (fields = fields , db = db , process_pools = process_pools ))
543545
544546 if errors :
545547 raise ValidationError (errors )
@@ -576,7 +578,9 @@ async def _process_fields_relationships(self, fields: dict, db: InfrahubDatabase
576578
577579 return errors
578580
579- async def _process_fields_attributes (self , fields : dict , db : InfrahubDatabase ) -> list [ValidationError ]:
581+ async def _process_fields_attributes (
582+ self , fields : dict , db : InfrahubDatabase , process_pools : bool
583+ ) -> list [ValidationError ]:
580584 errors : list [ValidationError ] = []
581585
582586 for attr_schema in self ._schema .attributes :
@@ -601,9 +605,10 @@ async def _process_fields_attributes(self, fields: dict, db: InfrahubDatabase) -
601605 )
602606 if not self ._existing :
603607 attribute : BaseAttribute = getattr (self , attr_schema .name )
604- await self .handle_pool (db = db , attribute = attribute , errors = errors )
608+ await self .handle_pool (db = db , attribute = attribute , errors = errors , allocate_resources = process_pools )
605609
606- attribute .validate (value = attribute .value , name = attribute .name , schema = attribute .schema )
610+ if process_pools or attribute .from_pool is None :
611+ attribute .validate (value = attribute .value , name = attribute .name , schema = attribute .schema )
607612 except ValidationError as exc :
608613 errors .append (exc )
609614
@@ -731,7 +736,7 @@ async def process_label(self, db: InfrahubDatabase | None = None) -> None: # no
731736 self .label .value = " " .join ([word .title () for word in self .name .value .split ("_" )])
732737 self .label .is_default = False
733738
734- async def new (self , db : InfrahubDatabase , id : str | None = None , ** kwargs : Any ) -> Self :
739+ async def new (self , db : InfrahubDatabase , id : str | None = None , process_pools : bool = True , ** kwargs : Any ) -> Self :
735740 if id and not is_valid_uuid (id ):
736741 raise ValidationError ({"id" : f"{ id } is not a valid UUID" })
737742 if id :
@@ -741,7 +746,7 @@ async def new(self, db: InfrahubDatabase, id: str | None = None, **kwargs: Any)
741746
742747 self .id = id or str (UUIDT ())
743748
744- await self ._process_fields (db = db , fields = kwargs )
749+ await self ._process_fields (db = db , fields = kwargs , process_pools = process_pools )
745750 await self ._process_macros (db = db )
746751
747752 return self
@@ -1046,15 +1051,15 @@ async def to_graphql(
10461051
10471052 return response
10481053
1049- async def from_graphql (self , data : dict , db : InfrahubDatabase ) -> bool :
1054+ async def from_graphql (self , data : dict , db : InfrahubDatabase , process_pools : bool = True ) -> bool :
10501055 """Update object from a GraphQL payload."""
10511056
10521057 changed = False
10531058
10541059 for key , value in data .items ():
10551060 if key in self ._attributes and isinstance (value , dict ):
10561061 attribute = getattr (self , key )
1057- changed |= await attribute .from_graphql (data = value , db = db )
1062+ changed |= await attribute .from_graphql (data = value , db = db , process_pools = process_pools )
10581063
10591064 if key in self ._relationships :
10601065 rel : RelationshipManager = getattr (self , key )
0 commit comments