fix: preserve nullable nested input presence in gRPC compiler#1447
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughCentralizes retrieval of field data ( Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client (JSON input)
participant Compiler as ProtoCompiler
participant Resolver as FieldResolver (uses gjson)
participant Builder as RPCMessage Builder
Client->>Compiler: Provide JSON input for RPC payload
Compiler->>Resolver: data.Get(rpcField.JSONPath) -> fieldData
Resolver-->>Compiler: fieldData (gjson.Result)
alt isNonNullValue(fieldData)
Compiler->>Builder: recurse/process field using fieldData
Builder-->>Compiler: built field value
else not non-null
alt field is required
Compiler-->>Client: return error (missing required field)
else optional
Compiler->>Builder: skip or leave unset
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can generate a title for your PR based on the changes.Add |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
v2/pkg/engine/datasource/grpc_datasource/compiler_input_presence_test.go (1)
33-107: Add one required-field negative case to lock the new error path.This suite is strong for optional semantics. Since compiler.go now errors on missing required nested inputs, add a case that marks
conditionsas non-optional and asserts errors for{}and{"conditions":null}.🧪 Suggested test addition
+func TestCompileRequiredNestedInputRejectsNullOrOmitted(t *testing.T) { + compiler, err := NewProtoCompiler(protoSchemaWithOptionalNestedInputs, nil) + require.NoError(t, err) + + inputMessage, ok := compiler.doc.MessageByName("UpdateRuleRequest") + require.True(t, ok) + + requiredConditions := &RPCMessage{ + Name: "UpdateRuleRequest", + Fields: RPCFields{ + { + Name: "conditions", + ProtoTypeName: DataTypeMessage, + JSONPath: "conditions", + Optional: false, + Message: &RPCMessage{ + Name: "ConditionsInput", + Fields: RPCFields{ + { + Name: "key", + ProtoTypeName: DataTypeString, + JSONPath: "key", + Optional: true, + }, + }, + }, + }, + }, + } + + for _, input := range []string{`{}`, `{"conditions":null}`} { + _, err := compiler.buildProtoMessage(inputMessage, requiredConditions, gjson.Parse(input)) + require.Error(t, err) + require.Contains(t, err.Error(), "field conditions is required") + } +}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@v2/pkg/engine/datasource/grpc_datasource/compiler_input_presence_test.go` around lines 33 - 107, Add a negative test case to TestCompileOptionalNestedInputsTreatsNullAsAbsent that exercises the new "required nested input" error path by using a schema where the conditions field is non-optional and asserting that building the message errors for both `{}` and `{"conditions":null}`; update the test to instantiate NewProtoCompiler with a modified schema (copy/variant of protoSchemaWithOptionalNestedInputs where conditions is required), call compiler.buildProtoMessage with optionalNestedInputsMessage() and the two inputs, and require an error (require.Error) instead of a successful build, referencing the existing test harness (TestCompileOptionalNestedInputsTreatsNullAsAbsent, NewProtoCompiler, protoSchemaWithOptionalNestedInputs, optionalNestedInputsMessage, buildProtoMessage, UpdateRuleRequest) so the new failing path is locked in.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@v2/pkg/engine/datasource/grpc_datasource/compiler.go`:
- Around line 1060-1062: The comment above the continue in the block that checks
hasConcreteValue(fieldData) is misleading: replace “provide a null message” with
wording that correctly states the field will be left absent/omitted (no protobuf
presence) when we don't have a value; update the comment near the
hasConcreteValue(fieldData) check in compiler.go to say it skips the field
resulting in an absent field rather than a null message.
---
Nitpick comments:
In `@v2/pkg/engine/datasource/grpc_datasource/compiler_input_presence_test.go`:
- Around line 33-107: Add a negative test case to
TestCompileOptionalNestedInputsTreatsNullAsAbsent that exercises the new
"required nested input" error path by using a schema where the conditions field
is non-optional and asserting that building the message errors for both `{}` and
`{"conditions":null}`; update the test to instantiate NewProtoCompiler with a
modified schema (copy/variant of protoSchemaWithOptionalNestedInputs where
conditions is required), call compiler.buildProtoMessage with
optionalNestedInputsMessage() and the two inputs, and require an error
(require.Error) instead of a successful build, referencing the existing test
harness (TestCompileOptionalNestedInputsTreatsNullAsAbsent, NewProtoCompiler,
protoSchemaWithOptionalNestedInputs, optionalNestedInputsMessage,
buildProtoMessage, UpdateRuleRequest) so the new failing path is locked in.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 06092c95-9523-41c2-8ed8-f81b5678d444
📒 Files selected for processing (2)
v2/pkg/engine/datasource/grpc_datasource/compiler.gov2/pkg/engine/datasource/grpc_datasource/compiler_input_presence_test.go
- Rename hasConcreteValue to isNonNullValue per reviewer suggestion - Fix misleading comment: "provide a null message" -> "leave it unset (absent)" - Add t.Parallel() to test function Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@Noroth I've pushed a commit addressing your review comments — renamed |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@Noroth Could you please re-trigger the CI? I've fixed the tparallel lint issue by adding |
🤖 I have created a release *beep* *boop* --- ## [2.0.0-rc.266](v2.0.0-rc.265...v2.0.0-rc.266) (2026-03-26) ### Features * add support for composite types in go-tools ([#1448](#1448)) ([646ea97](646ea97)) ### Bug Fixes * preserve nullable nested input presence in gRPC compiler ([#1447](#1447)) ([900d450](900d450)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for composite types in go-tools. * **Bug Fixes** * Fixed handling of nullable nested input presence in gRPC compiler. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Testing
Refs wundergraph/cosmo#2650
Summary by CodeRabbit
Bug Fixes
Tests