Skip to content

query: honor Encoder on interface fields#187

Merged
willnorris merged 1 commit into
google:masterfrom
c-tonneslan:encoder-interface-fields
Jul 6, 2026
Merged

query: honor Encoder on interface fields#187
willnorris merged 1 commit into
google:masterfrom
c-tonneslan:encoder-interface-fields

Conversation

@c-tonneslan

Copy link
Copy Markdown
Contributor

reflectValue checks sv.Type().Implements(encoderType) on the static field type. When a field is declared as interface{}, that type is the empty interface, which doesn't implement Encoder, so a value stored there never gets its EncodeValues method called and falls back to default formatting (e.g. v=[a b] instead of v.0=a&v.1=b).

Unwrapping the interface to its concrete value before the check fixes it, and lets the value be formatted by its dynamic type in general. Added an interface{}-field case to TestValues_CustomEncodingSlice; it produced v=[a b] before the change.

Fixes #121

reflectValue checked sv.Type().Implements(encoderType) against the static
field type, so a value stored in an interface{} field never used its
EncodeValues method and fell back to default formatting. Unwrap the interface
first so the concrete type's Encoder is seen.

Fixes google#121

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@willnorris

Copy link
Copy Markdown
Collaborator

looks good to me, thanks!

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7af347e) to head (121e633).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #187   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          165       140   -25     
=========================================
- Hits           165       140   -25     

☔ View full report in Codecov by Harness.
📢 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.

@willnorris willnorris merged commit d39ef06 into google:master Jul 6, 2026
13 checks passed
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.

Encoder interface not respected for interface{} types

2 participants