fix: scope artifact/generator regeneration for complex uniqueness constraints#9487
fix: scope artifact/generator regeneration for complex uniqueness constraints#9487FragmentedPacket wants to merge 4 commits into
Conversation
…straints The proposed-change artifact/generator validator decides whether it can limit regeneration to the changed objects via `only_has_unique_targets`. That check previously recognized a query as single-target only when it filtered by a required `ids` argument or by a node whose schema had exactly one uniqueness constraint made of exactly one attribute. As a result, queries that filter by a composite uniqueness constraint, by a node carrying more than one uniqueness constraint, by a relationship-based constraint, or by `hfid` were treated as non-unique and forced a full regeneration of every target in the group on any relevant change. Generalize the determination to the same model the uniqueness checker uses: a query targets a single object when it filters by a required single `ids` or `hfid` value, or when every component of at least one uniqueness constraint is pinned by a required, single-valued argument. Relationship components are pinned by a single `<rel>__ids`/`<rel>__hfid` value and only when the relationship is single-cardinality. Closes #9486 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 4 files
Confidence score: 3/5
- There is a concrete regression risk in
backend/infrahub/graphql/analyzer.py: required list variables are being handled as single-valued filters, which can produce false single-target detection. - Given the issue is medium severity (6/10) with high confidence (8/10) and affects query analysis behavior, this introduces meaningful user-facing correctness risk if merged as-is.
- Pay close attention to
backend/infrahub/graphql/analyzer.py- list-variable filter handling may misclassify multi-target queries as single-target.
Shadow auto-approve: would not auto-approve because issues were found.
Re-trigger cubic
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…int pin A required list-typed variable used to pin a uniqueness-constraint component (e.g. `color__ids: $colors` with `$colors: [ID!]!`) was treated as resolving to a single value, so a query filtering by such a list could be misclassified as targeting a single object and skip regenerating some stale artifacts. Constraint-component pinning now rejects required list variables; only a single-element list literal, a static value, or a required scalar variable pins a component. The top-level `ids`/`hfid` target selector keeps accepting a required list variable, since the artifact framework drives it per target member. Issue identified by cubic. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Addressed in b71208b — thanks, this was a valid catch identified by cubic. The flagged line treated any required variable (including a list-typed one) as single-valued. For the top-level The real risk was in the new uniqueness-constraint pinning path: a relationship component filtered by a required list variable (e.g. Fix: constraint-component pinning now rejects required list variables (only a single-element list literal, a static value, or a required scalar variable pins a component); the top-level selector keeps the per-member leniency via an explicit
|
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Shadow auto-approve: would require human review. This change modifies core artifact/generator regeneration logic by broadening how unique targets are detected, which directly impacts production behavior for proposed changes and could introduce subtle bugs in scoping artifact regeneration for composite, multiple, relationship-based, or hfid...
Re-trigger cubic
…etection Add a node with `[["name__value"], ["name__value", "serial_number__value"]]` to verify that satisfying the smaller subset group alone marks the query as single-target, while pinning only the field unique to the larger group does not. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Shadow auto-approve: would require human review. This change modifies core logic for determining artifact regeneration scope, which could lead to under-generation if detection is incorrect, and despite thorough testing and a safe fallback, the complexity justifies a human review.
Re-trigger cubic
Summary
During a proposed change, the artifact/generator validator decides whether it can limit regeneration to the objects that actually changed, or whether it must regenerate every target in the definition's group. That decision is driven by
only_has_unique_targetson the GraphQL query analyzer.Previously a query was recognized as targeting a single object only when it filtered by a required
idsargument, or by a node whose schema had exactly one uniqueness constraint made of exactly one attribute (with the filter argument name matching that attribute). Any other shape fell back to regenerating all targets and logged:This penalized several standard, recommended schema patterns:
namespace__value+name__value),name__value+site),hfid:).It also degraded silently: a definition whose query was scoped correctly would start regenerating all targets the moment a second uniqueness constraint was added to the node's schema, with no change to the query or definition.
Change
only_has_unique_targetsnow applies the same model the uniqueness checker uses. A root query resolves to a single object when:idsorhfidargument, orComponent pinning:
attr__value→ a required, single-valuedattr__valueargument,<rel>__idsor<rel>__hfidargument, and only when the relationship is single-cardinality.The fallback path was always functionally correct; this is a scope/performance improvement — more changes now regenerate only the affected artifacts instead of the whole group.
Notes
ids: $idslist variable counting as unique, as the artifact framework drives it per target).targets_unique_nodesfield description onInfrahubGraphQLQueryReportwas updated to match.Tests
test_query_report_single_targetcoverage with a newtest_query_report_single_target_complex_constraintsexercising composite, multiple, relationship-based, and hfid constraints (both pinned and unpinned cases).test_validate_artifacts_generation.py) and theInfrahubGraphQLQueryReportresolver tests still pass.Closes #9486
🤖 Generated with Claude Code
Summary by cubic
Improve artifact/generator regeneration by correctly detecting single-target GraphQL queries using composite, multiple, overlapping, relationship-based uniqueness constraints, or
hfid. Also fixes a misclassification when required list variables were used to pin uniqueness components, avoiding unnecessary full-group rebuilds.idsorhfid, or pins every component of at least one uniqueness constraint (including composites, overlapping/multiple groups, and single-cardinality relationships via<rel>__ids/<rel>__hfid).ids/hfid.GraphQLQueryReport.targets_unique_nodesdescription and regenerated the GraphQL schema. Added tests for composite, overlapping and multi-constraint, relationship,hfid, and list-variable cases.Written for commit bd452fe. Summary will update on new commits.