Skip to content

IFC-1681: Fix variable nested data#9282

Open
solababs wants to merge 4 commits into
stablefrom
fix-variable-nested-data-ifc-1681
Open

IFC-1681: Fix variable nested data#9282
solababs wants to merge 4 commits into
stablefrom
fix-variable-nested-data-ifc-1681

Conversation

@solababs
Copy link
Copy Markdown
Contributor

@solababs solababs commented May 18, 2026

Why

graphene.GenericScalar.parse_literal does not forward _variables to its recursive calls when processing nested ObjectValueNode or ListValueNode AST nodes, and does not handle VariableNode at all. As a result, any $variable reference inside the data sub-object of IPPrefixPoolGetResource or IPAddressPoolGetResource is silently coerced to null instead of its supplied value.

Closes #6850

What changed

  • New scalar FixedGenericScalar in backend/infrahub/graphql/scalars.py — a GenericScalar subclass whose parse_literal correctly forwards _variables to recursive calls and resolves VariableNode by looking up the variable name in the provided map.
  • IPPrefixPoolGetResourceInput.data and IPAddressPoolGetResourceInput.data in resource_manager.py switched from GenericScalar to FixedGenericScalar.

How to test

uv run pytest backend/tests/component/graphql/resource_manager/test_resource_manager_data_variables.py -v

# Full regression
uv run pytest backend/tests/component/graphql/resource_manager/ -v

Checklist

  • Tests added/updated
  • Changelog entry added (changelog/6850.fixed.md)
  • External docs updated (if user-facing or ops-facing change)
  • Internal .md docs updated (internal knowledge and AI code tools knowledge)
  • I have reviewed AI generated content

Summary by cubic

Fixes GraphQL variable substitution inside the data field for pool allocation mutations. Addresses IFC-1681 by ensuring nested variables resolve instead of becoming null.

  • Bug Fixes
    • Added FixedGenericScalar to replace graphene.GenericScalar parsing, forwarding _variables and resolving VariableNode.
    • Switched IPPrefixPoolGetResourceInput.data and IPAddressPoolGetResourceInput.data to FixedGenericScalar, and updated the GraphQL schema to expose this scalar and reflect the input changes.
    • Updated frontend generated GraphQL types to include FixedGenericScalar and the new input field types.
    • Added component tests verifying variables set description correctly in InfrahubIPPrefixPoolGetResource and InfrahubIPAddressPoolGetResource.
    • Added unit tests for FixedGenericScalar.parse_literal, covering nested lists/objects, variables, and numeric bounds.

Written for commit 21310e0. Summary will update on new commits. Review in cubic

@solababs solababs requested a review from a team as a code owner May 18, 2026 22:20
@github-actions github-actions Bot added the group/backend Issue related to the backend (API Server, Git Agent) label May 18, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. This PR fixes a targeted GraphQL variable substitution bug by introducing a dedicated scalar that forwards _variables to recursive calls and resolves VariableNode, swapped only in two pool mutation input fields, with comprehensive tests confirming correct behavior and no changes to core logic...

Re-trigger cubic

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 18, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing fix-variable-nested-data-ifc-1681 (21310e0) with stable (72c3033)

Open in CodSpeed

@github-actions github-actions Bot added the group/frontend Issue related to the frontend (React) label May 19, 2026
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like the tests only cover the string path of the new FixedGenericScalar. it would be good if the tests covered all the paths. I think it would require creating a new NodeSchema that inherits from BuiltinIPPrefix and includes attributes that cover all of the various paths from the new logic: string, bool, float, etc.

Comment thread backend/infrahub/graphql/scalars.py Outdated
"""

@staticmethod
def parse_literal(ast: ValueNode, _variables: dict[str, Any] | None = None) -> Any: # noqa: PLR0911
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if you set a variable to return and then only return it at the end, you can get ride of the PLR0911 ignore

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Shadow auto-approve: would auto-approve. This change fixes a GraphQL variable resolution bug in two specific mutation inputs with a focused new scalar and comprehensive tests, having no broader system impact or risk to critical logic.

Re-trigger cubic

@solababs solababs requested a review from ajtmccarty May 25, 2026 07:44
Copy link
Copy Markdown
Contributor

@ajtmccarty ajtmccarty left a comment

Choose a reason for hiding this comment

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

should the new FixedGenericScalar class be used throughout our graphql logic in place of the GenericScalar that does not support variables? probably worth a follow-up issue to track it

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) group/frontend Issue related to the frontend (React)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: cannot use a variable in the data property of IPPrefixPoolGetResourceInput input type used in the IPPrefixPoolGetResource GraphQL mutation

2 participants