fix: incorrect alias behavior for required fields#1604
Conversation
📝 WalkthroughWalkthroughFederation ChangesFederation Requires Aliases
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Claude Code Review
Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.
Tip: disable this comment in your organization's Code Review settings.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor_federation.go (1)
440-467: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winCloned entry's fields get overwritten by stale data —
requiredFieldlocal var never repointed to the clone.In the
elsebranch (append-clone path),requiredField.clone()is appended intoconfig.requiredFields, but the localrequiredFieldvariable is never reassigned to that clone — it still holds the previously-bound entry. The subsequent lines (requiredField.ref = ref,.fieldDefRef = fieldDefRef,.resultField = field) mutate this stale value, andfieldArgumentsis only overwritten when the current occurrence has arguments (len(fieldArgs) > 0). If the current (aliased) occurrence has no arguments while the previously-bound entry did, the stalefieldArgumentsleaks into the newly appended entry at line 467, silently overwriting the intentionally-cleared clone.Example:
nullableFilteredTagSummary(prefix: $prefix)plus an aliased selection of the same field without the argument would send the wrong (stale)prefixargument for the aliased required-fields call.🐛 Proposed fix
} else { index = len(config.requiredFields) - config.requiredFields = append(config.requiredFields, requiredField.clone()) + requiredField = requiredField.clone() + config.requiredFields = append(config.requiredFields, requiredField) r.entityConfig.setEntity(r.entityInfo.typeName, config) }Consider adding a regression test (e.g. in
execution_plan_requires_test.go) combining an aliased selection with a field that has optional arguments, to catch this class of bug.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor_federation.go` around lines 440 - 467, In the clone branch of the required-field handling logic, repoint the requiredField local variable to the newly appended clone and update index accordingly before mutating ref, fieldDefRef, resultField, and fieldArguments. Ensure each response-key entry starts with the clone’s cleared argument state when the current occurrence has no arguments, preventing stale arguments from the previously bound entry from being copied.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In
`@v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor_federation.go`:
- Around line 440-467: In the clone branch of the required-field handling logic,
repoint the requiredField local variable to the newly appended clone and update
index accordingly before mutating ref, fieldDefRef, resultField, and
fieldArguments. Ensure each response-key entry starts with the clone’s cleared
argument state when the current occurrence has no arguments, preventing stale
arguments from the previously bound entry from being copied.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b6cac6bd-a5ec-476f-ba15-d06bf8261d65
📒 Files selected for processing (4)
v2/pkg/engine/datasource/grpc_datasource/execution_plan.gov2/pkg/engine/datasource/grpc_datasource/execution_plan_requires_test.gov2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor_federation.gov2/pkg/engine/datasource/grpc_datasource/grpc_datasource_federation_test.go
Aliases are not correctly taken into accoutn when using required fields. This PR fixes the behavior.
@coderabbitai summary
Checklist
Open Source AI Manifesto
This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.