-
Notifications
You must be signed in to change notification settings - Fork 6
fix: resolve from_pool string names to pool IDs in object spec #862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle UUID
from_poolstrings before doing an HFID lookup.Right now every plain string goes through
hfid=[from_pool]on Line 454. If callers pass a pool UUID string instead of a name, this path misses the direct-id case even though the mutation payload wants{"id": "<uuid>"}.💡 Suggested fix
async def _resolve_attribute_pool( cls, client: InfrahubClient, schema: MainSchemaTypesAPI, name: str, value: Any, branch: str | None = None, ) -> Any: """If an attribute value has from_pool as a plain string name, resolve it to {id: uuid}.""" if not isinstance(value, dict) or "from_pool" not in value: return value from_pool = value["from_pool"] if not isinstance(from_pool, str): return value + if is_valid_uuid(from_pool): + return {**value, "from_pool": {"id": from_pool}} attr_schema = schema.get_attribute_or_none(name=name) if attr_schema is None: return value pool_kind = _ATTRIBUTE_KIND_TO_POOL_KIND.get(attr_schema.kind) if pool_kind is None: return value pool = await client.get(kind=pool_kind, hfid=[from_pool], branch=branch, raise_when_missing=True) return {**value, "from_pool": {"id": pool.id}}🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the bot highlights a valid point here, since we have
is_valid_uuid, we could check if the string is a valid UUID prior to making a HFID-based query. That would spare us a possible useless query.Also can you add a test to validate how the fix should behave and prevent possible regressions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 5195
🏁 Script executed:
Length of output: 26453
🏁 Script executed:
Length of output: 88643
@gmazoyer, agreed on both points — the UUID fast-path is a valid improvement that avoids a redundant network round-trip. Here's the plan:_resolve_attribute_poolbefore the HFID query_resolve_attribute_pooldirectly, covering all four cases💡 Use
@coderabbitaiplan to create a plan for code changes