Skip to content

🐛 bug: Fix binder splitting for pointer-backed slice fields#3844

Merged
ReneWerner87 merged 1 commit intomainfrom
enhance-pointer-handling-in-equalfieldtype
Nov 6, 2025
Merged

🐛 bug: Fix binder splitting for pointer-backed slice fields#3844
ReneWerner87 merged 1 commit intomainfrom
enhance-pointer-handling-in-equalfieldtype

Conversation

@gaby
Copy link
Member

@gaby gaby commented Nov 6, 2025

Summary

  • unwrap pointer types when building binder field metadata so pointer-backed slices are detected for splitting
  • extend equalFieldType tests with pointer slice and nested pointer struct coverage
  • add a query binder regression test that binds comma-separated values into pointer slices when splitting is enabled

Copilot AI review requested due to automatic review settings November 6, 2025 12:14
@gaby gaby requested a review from a team as a code owner November 6, 2025 12:14
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Walkthrough

Introduces a unwrapType() helper function to dereference pointer types and updates field type analysis in the mapping logic to use unwrapped types instead of direct pointer inspection. Extends test coverage for pointer slices, nested structs, and pointer-to-pointer scenarios in binding operations.

Changes

Cohort / File(s) Summary
Type dereferencing logic
binder/mapping.go
Added unwrapType() helper to iteratively dereference pointer types. Updated field inspection to use unwrapped types when analyzing field kinds and nested struct fields, replacing direct f.Type and sf.Type calls with dereferenced equivalents.
Test coverage expansion
binder/mapping_test.go, binder/query_test.go
Extended Test_EqualFieldType with cases for pointer slices and nested struct/pointer combinations. Added Test_QueryBinder_Bind_PointerSlices to validate binding behavior for pointer slices in both top-level and nested contexts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to the unwrapType() implementation and ensure pointer dereferencing handles all edge cases correctly
  • Verify all call sites where field types are inspected now use the unwrapped type consistently
  • Review test cases to confirm they cover the new pointer unwrapping scenarios comprehensively

Suggested labels

☢️ Bug, v3

Suggested reviewers

  • sixcolors
  • efectn
  • ReneWerner87

Poem

🐰 Pointers unwrapped, no more confusion,
Through layers of types, we seek the illusion,
Nested structs and slices align,
Reflection now works by design! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides a clear summary of changes but does not follow the required template structure with sections like 'Changes introduced', 'Type of change', and 'Checklist'. Expand the description to include the required template sections: 'Changes introduced' with checkboxes, 'Type of change' selection, and 'Checklist' items for code review requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing binder splitting for pointer-backed slice fields, which is the core purpose of this PR.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhance-pointer-handling-in-equalfieldtype

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff04aa0 and 1efdf72.

📒 Files selected for processing (3)
  • binder/mapping.go (2 hunks)
  • binder/mapping_test.go (1 hunks)
  • binder/query_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Apply formatting using gofumpt (Make target: format)
Optimize struct field alignment using betteralign (Make target: betteralign)
Modernize code using gopls modernize (Make target: modernize)

Files:

  • binder/mapping_test.go
  • binder/mapping.go
  • binder/query_test.go
🧠 Learnings (1)
📚 Learning: 2024-12-13T08:14:22.851Z
Learnt from: efectn
Repo: gofiber/fiber PR: 3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.

Applied to files:

  • binder/mapping_test.go
🧬 Code graph analysis (1)
binder/query_test.go (2)
binder/query.go (2)
  • QueryBinding (9-11)
  • QueryBinding (14-16)
client/request.go (2)
  • AcquireRequest (983-989)
  • ReleaseRequest (993-996)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Cleanup artifacts
  • GitHub Check: Compare
  • GitHub Check: unit (1.25.x, macos-13)
  • GitHub Check: unit (1.25.x, macos-latest)
  • GitHub Check: unit (1.25.x, windows-latest)
  • GitHub Check: repeated
  • GitHub Check: lint
🔇 Additional comments (4)
binder/query_test.go (1)

88-122: Excellent test coverage for pointer slice binding!

This test comprehensively validates the pointer-unwrapping fix by covering:

  • Top-level pointer slice (Emails *[]string)
  • Nested pointer struct with pointer slice (Prefs.Tags *[]string)
  • Comma-separated value splitting with EnableSplitting: true

The test structure follows existing patterns, properly manages resources with cleanup, and uses require for assertions.

binder/mapping_test.go (1)

52-72: Thorough test coverage for pointer unwrapping in nested scenarios!

These test cases validate the unwrapping logic across increasingly complex scenarios:

  1. Direct pointer-to-slice (Tags *[]string)
  2. Pointer to nested struct with slice (Nested *nested with Values []string)
  3. Pointer to nested struct with pointer-to-slice (Nested *nestedPointerSlice with Values *[]string)

The progressive complexity ensures the unwrapping works correctly at multiple indirection levels.

binder/mapping.go (2)

223-229: Clean and effective pointer unwrapping helper!

The unwrapType function correctly handles multiple levels of pointer indirection using a simple loop. This is safe because Go's type system prevents cyclic pointer types, so the loop will always terminate.


270-282: Proper integration of unwrapping logic in field analysis!

The changes correctly apply unwrapType at all necessary points:

  • Line 270: Unwrap field type before recording its kind
  • Line 273: Check the unwrapped type to detect structs behind pointers
  • Lines 274-275: Use unwrapped type for nested field iteration
  • Line 279: Unwrap nested field types before recording their kinds

This ensures pointer-backed slices and nested pointer structures are correctly detected for splitting.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the binder failed to correctly process and split values for fields that are pointer-backed slices. By introducing a mechanism to unwrap pointer types during field metadata construction, the binder can now accurately identify the underlying slice types. This enhancement ensures robust data binding for complex Go struct definitions that leverage pointers, improving the reliability of query parameter parsing.

Highlights

  • Pointer Type Unwrapping: Introduced a new utility function, unwrapType, to recursively resolve the underlying type of a field, effectively handling pointer indirection.
  • Binder Field Metadata Correction: Updated the buildFieldInfo function to utilize unwrapType, ensuring that the binder correctly identifies the kind of pointer-backed slice fields for proper splitting.
  • Expanded Test Coverage: Added new test cases to equalFieldType in binder/mapping_test.go to specifically cover scenarios involving pointer slices and nested pointer structs, validating the type comparison logic.
  • Query Binder Regression Test: Included a new regression test, Test_QueryBinder_Bind_PointerSlices, to confirm that the QueryBinding mechanism correctly binds comma-separated values into pointer-backed slices, including those within nested structs, when splitting is enabled.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for pointer-to-slice field types in query parameter binding. Previously, the binder only handled direct slice types, but now it can correctly bind data to fields like *[]string.

Key changes:

  • Added unwrapType helper function to recursively dereference pointer types
  • Updated buildFieldInfo to unwrap pointer types when analyzing field kinds
  • Added comprehensive test coverage for pointer-to-slice scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
binder/mapping.go Adds unwrapType helper function and updates buildFieldInfo to handle pointer types by unwrapping them before determining their kind
binder/query_test.go Adds new test case Test_QueryBinder_Bind_PointerSlices to verify pointer-to-slice binding works correctly with both top-level and nested structures
binder/mapping_test.go Extends Test_EqualFieldType with test cases for pointer-to-slice types in simple, nested, and deeply nested scenarios

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an issue where the binder would not split comma-separated values for fields that are pointers to slices. The fix involves unwrapping pointer types using reflection to determine the underlying field type. The change is well-implemented and is accompanied by thorough unit and regression tests that cover various pointer and nesting scenarios. My review includes a minor suggestion to improve the readability of the new test cases.

@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.13%. Comparing base (ff04aa0) to head (1efdf72).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3844      +/-   ##
==========================================
- Coverage   92.18%   92.13%   -0.06%     
==========================================
  Files         115      115              
  Lines        9754     9760       +6     
==========================================
  Hits         8992     8992              
- Misses        484      489       +5     
- Partials      278      279       +1     
Flag Coverage Δ
unittests 92.13% <100.00%> (-0.06%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@gaby gaby changed the title Fix binder splitting for pointer-backed slice fields 🐛 bug: Fix binder splitting for pointer-backed slice fields Nov 6, 2025
@ReneWerner87 ReneWerner87 added this to v3 Nov 6, 2025
@ReneWerner87 ReneWerner87 added this to the v3 milestone Nov 6, 2025
@ReneWerner87 ReneWerner87 merged commit af49240 into main Nov 6, 2025
23 checks passed
@ReneWerner87 ReneWerner87 deleted the enhance-pointer-handling-in-equalfieldtype branch November 6, 2025 13:07
@github-project-automation github-project-automation bot moved this to Done in v3 Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants