Skip to content

allow updating pools by name#8492

Merged
ajtmccarty merged 4 commits intorelease-1.8from
ajtm-02262026-pool-by-name
Feb 27, 2026
Merged

allow updating pools by name#8492
ajtmccarty merged 4 commits intorelease-1.8from
ajtm-02262026-pool-by-name

Conversation

@ajtmccarty
Copy link
Contributor

@ajtmccarty ajtmccarty commented Feb 27, 2026

IFC-2300

should follow #8482

allow specifying resource pools (IP Prefix/Address and NumberPool) by name in the from_pool input. the name attribute is unique on the CoreResourcePool generic

for example

mutation {
    TestingTicketUpdate(data: {
        id: "abc"
        ticket_id: {
            from_pool: {
                id: "name of my NumberPool"
            }
        }
    }) {
        ok
    }
}

purposefully chose not to use NodeManager.get_by_id_or_default_filter b/c we are trying to not use default_filter any longer. instead this uses is_valid_uuid and tries to get by name using NodeManager.query if the input is not an ID.

added graphql component tests to cover the changes

  • creating and updating prefix and address pools using IDs and names on IP relationships
  • creating and updating number pools using IDs and names on Number attributes
  • negative tests for all the above cases with invalid names

also moved some of the test files around and removed string interpolation from some of the graphql query strings

Summary by CodeRabbit

  • New Features

    • Pools can be referenced by name or UUID in GraphQL mutations for creating/updating IP prefixes, IP addresses, and tickets; existing UUID behavior is preserved.
    • Clear user-facing errors returned when a referenced pool name does not exist.
  • Tests

    • Added comprehensive end-to-end tests covering pool lookup by name for IP and number pools, plus a test update ensuring schema hash refresh after schema registration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14e25c7 and fb61809.

📒 Files selected for processing (1)
  • backend/tests/component/graphql/test_mutation_upsert.py

Walkthrough

This pull request adds support for referencing resource pools by name in addition to UUID-based lookup. Core logic changes in node and relationship model files implement a fallback mechanism: when a pool identifier is not a valid UUID, the system queries the corresponding pool type by name instead. Two new comprehensive test suites validate pool lookup by name for both IP and number pool resources, covering creation, updates, and error scenarios. Additionally, test refactoring consolidates GraphQL mutation definitions into named constants for improved maintainability.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'allow updating pools by name' accurately and concisely summarizes the main change—enabling resource pools to be referenced by name instead of UUID in mutations.
Description check ✅ Passed The description covers the 'Why' (IFC-2300, follows #8482), 'What changed' (behavioral changes and implementation notes), and 'How to test' (test suite additions), but lacks explicit sections on backward compatibility, performance, and deployment notes required by the template.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Feb 27, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 27, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing ajtm-02262026-pool-by-name (fb61809) with release-1.8 (7ee81b7)

Open in CodSpeed

@ajtmccarty ajtmccarty marked this pull request as ready for review February 27, 2026 03:28
@ajtmccarty ajtmccarty requested a review from a team as a code owner February 27, 2026 03:28
default_branch_scope_class: Branch,
register_core_models_schema_scope_class: SchemaBranch,
) -> CoreNumberPool:
await load_schema(db=db, schema=SchemaRoot(nodes=[TICKET]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

)
else:
results = await registry.manager.query(
db=db, schema=InfrahubKind.NUMBERPOOL, filters={"name__value": number_pool_id}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker to make progress but number_pool would get different types compared to above where we are querying for CoreNumberPool instead of InfrahubKind.NUMBERPOOL. But the type checkers probably don't pick this up due to all of the ignore lines in pyproject.toml :(

results = await registry.manager.query(
db=db, schema=InfrahubKind.RESOURCEPOOL, filters={"name__value": pool_id}, branch=self.branch
)
results = cast("list[Node]", results)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that the problem here is that the type of the overload for NodeManager.query is incorrect and returns an Any instead of a Node. Once we change that (if it happens before the refactoring of those classes) I think this should resurface as a redundant cast, so we probably don't need to track it.

Base automatically changed from ajtm-02242026-validate-number-pool-id to release-1.8 February 27, 2026 14:42
@ajtmccarty ajtmccarty force-pushed the ajtm-02262026-pool-by-name branch from 1e1ac1c to 14e25c7 Compare February 27, 2026 15:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/infrahub/core/node/__init__.py`:
- Around line 407-414: The UUID and name lookups for number pools (the
is_valid_uuid branch using registry.manager.get_one with CoreNumberPool and the
else branch using registry.manager.query with InfrahubKind.NUMBERPOOL) are
missing the branch filter; update both calls to include the current branch (same
pattern used by the relationship resolver around lines 564-574) so that get_one
and query are scoped by branch (pass the branch argument or include {"branch":
branch} in filters) to avoid cross-branch resolution.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b93c29 and 14e25c7.

📒 Files selected for processing (6)
  • backend/infrahub/core/node/__init__.py
  • backend/infrahub/core/relationship/model.py
  • backend/tests/component/graphql/resource_manager/__init__.py
  • backend/tests/component/graphql/resource_manager/test_ip_pool_lookup_by_name.py
  • backend/tests/component/graphql/resource_manager/test_number_pool_lookup_by_name.py
  • backend/tests/component/graphql/resource_manager/test_resource_manager.py

Comment on lines +407 to +414
if is_valid_uuid(number_pool_id):
number_pool = await registry.manager.get_one(
db=db, id=number_pool_id, kind=CoreNumberPool, raise_on_error=True
)
else:
results = await registry.manager.query(
db=db, schema=InfrahubKind.NUMBERPOOL, filters={"name__value": number_pool_id}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect handle_pool lookup path
echo "=== Lines 404-418 of backend/infrahub/core/node/__init__.py ==="
sed -n '404,418p' backend/infrahub/core/node/__init__.py

echo ""
echo "=== Relationship resolver pool lookup (lines 564-574) ==="
sed -n '564,574p' backend/infrahub/core/relationship/model.py 2>/dev/null || echo "(File or lines not found)"

echo ""
echo "=== NodeManager.query signature ==="
rg -nP 'async def query\(' backend/infrahub/core/manager.py -A10 -B2 | head -30

echo ""
echo "=== Check for get_branch_based_on_support_type method ==="
rg -n 'def get_branch_based_on_support_type' backend/infrahub/core/node/__init__.py -B2 -A8

Repository: opsmill/infrahub

Length of output: 3036


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check if there are other calls to registry.manager.get_one for pools/numbers in the codebase
# to establish a pattern
echo "=== Other registry.manager.get_one calls for Node lookups in same file ==="
rg 'registry\.manager\.get_one' backend/infrahub/core/node/__init__.py -B1 -A3 | head -40

echo ""
echo "=== Check context around handle_pool method ==="
sed -n '390,425p' backend/infrahub/core/node/__init__.py

Repository: opsmill/infrahub

Length of output: 2350


Scope number-pool lookups to the current branch for both UUID and name paths.

Both the UUID lookup (line 409) and the name-based lookup (line 413) omit the branch parameter, causing potential cross-branch pool misresolution. The relationship resolver at lines 564-574 demonstrates the correct pattern with branch-scoped queries for both paths.

🔧 Proposed fix
         try:
+            lookup_branch = self.get_branch_based_on_support_type()
             if is_valid_uuid(number_pool_id):
                 number_pool = await registry.manager.get_one(
-                    db=db, id=number_pool_id, kind=CoreNumberPool, raise_on_error=True
+                    db=db, id=number_pool_id, kind=CoreNumberPool, branch=lookup_branch, raise_on_error=True
                 )
             else:
                 results = await registry.manager.query(
-                    db=db, schema=InfrahubKind.NUMBERPOOL, filters={"name__value": number_pool_id}
+                    db=db,
+                    schema=InfrahubKind.NUMBERPOOL,
+                    filters={"name__value": number_pool_id},
+                    branch=lookup_branch,
                 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/infrahub/core/node/__init__.py` around lines 407 - 414, The UUID and
name lookups for number pools (the is_valid_uuid branch using
registry.manager.get_one with CoreNumberPool and the else branch using
registry.manager.query with InfrahubKind.NUMBERPOOL) are missing the branch
filter; update both calls to include the current branch (same pattern used by
the relationship resolver around lines 564-574) so that get_one and query are
scoped by branch (pass the branch argument or include {"branch": branch} in
filters) to avoid cross-branch resolution.

@ajtmccarty ajtmccarty merged commit 1cbe9af into release-1.8 Feb 27, 2026
43 checks passed
@ajtmccarty ajtmccarty deleted the ajtm-02262026-pool-by-name branch February 27, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants