Skip to content

query: honor omitempty on embedded struct fields - #199

Merged
willnorris merged 1 commit into
google:masterfrom
Alifarid0011:fix/embedded-omitempty
Oct 28, 2026
Merged

willnorris merged 1 commit into
google:masterfrom
Alifarid0011:fix/embedded-omitempty

Conversation

@Alifarid0011

Copy link
Copy Markdown
Contributor

An anonymous struct tagged url:",omitempty" is queued for traversal before its emptiness is checked. A zero value with an IsZero() bool method therefore still adds its promoted fields to the query, while an explicitly named field of the same type is omitted.

Check omitempty before queuing embedded structs. The IsZero assertion also checks reflection accessibility so unexported embedded structs continue to expose their exported fields without panicking. Kind-based emptiness checks remain unchanged, including zero private scalar embeds and nil pointers; non-nil pointers still encode their contents.

Fixes #198.

Validation on Go 1.26.8, linux/amd64:

  • The new regression test fails on unchanged master (965d79f) with an unexpected empty query parameter, and passes with this change.
  • Ten table cases cover empty/nonempty embeds, named embeds, omission disabled, nil/non-nil pointers, private scalar embeds and exported fields promoted from a private struct. The test also passes across 100 repetitions.
  • go test -race -coverprofile coverage.txt -covermode atomic ./... — passes, 100% statement coverage.
  • go test -shuffle=on ./..., go vet ./..., and go build ./... — pass.
  • golangci-lint run ./... — zero issues with the repository's pinned v2.1.2 and its existing configuration.

Other Go versions are left to the upstream CI matrix. No dependencies or public APIs are added.

@codecov

codecov Bot commented Oct 28, 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 (f3d489e).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #199   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          165       127   -38     
=========================================
- Hits           165       127   -38     

☔ 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 854f399 into google:master Oct 28, 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.

query: omitempty is ignored on anonymous struct fields

2 participants