@@ -270,16 +270,17 @@ async def handle_pool(self, db: InfrahubDatabase, attribute: BaseAttribute, erro
270270 )
271271 except NodeNotFoundError :
272272 if number_pool_parameters :
273- await self ._create_number_pool (
274- db = db , attribute = attribute , errors = errors , number_pool_parameters = number_pool_parameters
273+ number_pool = await self ._create_number_pool (
274+ db = db , attribute = attribute , number_pool_parameters = number_pool_parameters
275275 )
276- return
277- errors .append (
278- ValidationError (
279- {f"{ attribute .name } .from_pool" : f"The pool requested { attribute .from_pool } was not found." }
276+
277+ else :
278+ errors .append (
279+ ValidationError (
280+ {f"{ attribute .name } .from_pool" : f"The pool requested { attribute .from_pool } was not found." }
281+ )
280282 )
281- )
282- return
283+ return
283284
284285 if (
285286 number_pool .node .value in [self ._schema .kind ] + self ._schema .inherit_from
@@ -305,8 +306,8 @@ async def handle_pool(self, db: InfrahubDatabase, attribute: BaseAttribute, erro
305306 )
306307
307308 async def _create_number_pool (
308- self , db : InfrahubDatabase , attribute : BaseAttribute , errors : list , number_pool_parameters : NumberPoolParameters
309- ) -> None :
309+ self , db : InfrahubDatabase , attribute : BaseAttribute , number_pool_parameters : NumberPoolParameters
310+ ) -> CoreNumberPool :
310311 schema = db .schema .get_node_schema (name = "CoreNumberPool" , duplicate = False )
311312
312313 pool_node = self ._schema .kind
@@ -329,7 +330,9 @@ async def _create_number_pool(
329330 end_range = number_pool_parameters .end_range ,
330331 )
331332 await number_pool .save (db = db )
332- await self .handle_pool (db = db , attribute = attribute , errors = errors )
333+ # Do a lookup of the number pool to get the correct mapped type from the registry
334+ # without this we don't get access to the .get_resource() method.
335+ return await registry .manager .get_one_by_id_or_default_filter (db = db , id = number_pool .id , kind = CoreNumberPool )
333336
334337 async def handle_object_template (self , fields : dict , db : InfrahubDatabase , errors : list ) -> None :
335338 """Fill the `fields` parameters with values from an object template if one is in use."""
0 commit comments