Skip to content

Commit 0a1e88b

Browse files
committed
Address feedback
1 parent 27070dd commit 0a1e88b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

backend/infrahub/core/node/__init__.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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."""

backend/infrahub/core/schema/attribute_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async def get_query_filter(
204204
class NumberPoolSchema(AttributeSchema):
205205
parameters: NumberPoolParameters = Field(
206206
default_factory=NumberPoolParameters,
207-
description="Extra parameters specific to text attributes",
207+
description="Extra parameters specific to NumberPool attributes",
208208
json_schema_extra={"update": UpdateSupport.VALIDATE_CONSTRAINT.value},
209209
)
210210

0 commit comments

Comments
 (0)