Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(utils): extract the fields of an inline fragment nested in another - #1569

Open
polmichel wants to merge 2 commits into
pog-em/analyzer-resolve-top-level-fragmentsfrom
pog-em/extract-fields-nested-inline-fragment
Open

polmichel wants to merge 2 commits into
pog-em/analyzer-resolve-top-level-fragmentsfrom
pog-em/extract-fields-nested-inline-fragment

Conversation

@polmichel

@polmichel polmichel commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1557.

A nested inline fragment made extract_fields raise

extract_fields (infrahub_sdk/utils.py) read .name on every child of an inline fragment. An inline fragment written inside another inline fragment has no name, so the call raised AttributeError: 'InlineFragmentNode' object has no attribute 'name'. GraphQLQueryAnalyzer.get_fields, calculate_depth and calculate_height raised the same error.

Infrahub calls calculate_depth for its metrics after it runs an operation. On a live stack that ran opsmill/infrahub#11815:

  • query { ... on Query { ... { BuiltinTag { count } } } } returned HTTP 500, also without credentials.
  • A mutation written the same way and sent by the admin created its node, and the response was still HTTP 500.

infrahub_sdk/utils.py is identical at daf2fa02, the commit Infrahub stable pins.

An inline fragment now contributes what extract_fields returns for its selection set

  • The fields of a nested inline fragment are reported at the level of the enclosing fragment.
  • A fragment spread inside an inline fragment is skipped, as it already was outside one. Before, it was reported as a field named after the fragment: ... on TestPerson { id ...Names } gave {"id": None, "Names": None}.

A field selected twice lost sub-fields

Reported by cubic on this pull request. The behavior is older than this pull request and does not need a fragment.

  • cars { edges { node { id } } } cars { edges { node { name { value } } } } reported only name under node. Both are now reported.
  • cars cars { id } reported cars without sub-fields. It now reports id.

The merge used dict.update; it now uses deep_merge_dict. The depth and height of such a query can be higher than before. Fixed in its own commit, with 5 test cases in test_extract_fields_merges_a_field_selected_twice, 4 of which fail without it.

Tests

Written first. For the nested inline fragment, all 6 fail without the fix.

  • test_extract_fields_nested_inline_fragment: 4 cases (at the operation root, below a field, three levels, merged with the same field of the enclosing fragment).
  • test_extract_fields_ignores_fragment_spread_in_inline_fragment.
  • test_depth_and_height_of_nested_inline_fragments: a query has the same fields, depth and height written plainly or inside nested inline fragments.

On the same live stack with python_sdk moved to this branch (60bed4a4):

  • The anonymous nested query returns HTTP 200 with its data.
  • The admin's nested mutation returns HTTP 200 and creates its node.
  • The anonymous nested mutation is still refused with HTTP 401 and creates nothing.

Not run against Infrahub's CI yet.

🤖 Generated with Claude Code

extract_fields read .name on every child of an inline fragment, so a
nested inline fragment raised AttributeError. Infrahub calls it through
GraphQLQueryAnalyzer.calculate_depth after it runs an operation, and
answered such a query with HTTP 500.

An inline fragment now contributes the fields that extract_fields
returns for its selection set. A fragment spread inside an inline
fragment is skipped, as it already was outside one, instead of being
reported as a field named after the fragment.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 393241e
Status: ✅  Deploy successful!
Preview URL: https://ad33c7e3.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-em-extract-fields-nested.infrahub-sdk-python.pages.dev

View logs

@polmichel
polmichel requested a review from a team as a code owner December 1, 2026 14:10
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                               Coverage Diff                               @@
##           pog-em/analyzer-resolve-top-level-fragments    #1569      +/-   ##
===============================================================================
+ Coverage                                        87.90%   87.95%   +0.04%     
===============================================================================
  Files                                              157      157              
  Lines                                            15674    15669       -5     
  Branches                                          2118     2116       -2     
===============================================================================
+ Hits                                             13779    13782       +3     
+ Misses                                            1334     1330       -4     
+ Partials                                           561      557       -4     
Flag Coverage Δ
integration-tests 42.96% <0.00%> (+0.01%) ⬆️
python-3.10 63.10% <88.88%> (+0.03%) ⬆️
python-3.11 63.10% <88.88%> (+0.04%) ⬆️
python-3.12 63.09% <88.88%> (+0.03%) ⬆️
python-3.13 63.10% <88.88%> (+0.03%) ⬆️
python-3.14 63.10% <88.88%> (+0.04%) ⬆️
python-3.15 63.10% <88.88%> (+0.04%) ⬆️
python-filler-3.12 23.05% <11.11%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/utils.py 91.50% <100.00%> (+3.03%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

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.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread infrahub_sdk/utils.py Resolved
@polmichel
polmichel marked this pull request as draft December 1, 2026 14:17
extract_fields merged two selections of the same field with dict.update,
which replaced the nested dictionaries of the first selection. For
`cars { edges { node { id } } } cars { edges { node { name } } }` only
`name` remained under `node`. A field selected first without
sub-fields and then with them kept none.

The merge now uses deep_merge_dict, so the selections are combined at
every level.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@polmichel
polmichel added this pull request to stack #1571 December 1, 2026 15:14
@polmichel
polmichel marked this pull request as ready for review December 1, 2026 15:15

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

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.

No issues found across 5 files

View guided diff | Turn on auto-fix | Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant