Skip to content

Preserve nil values when flattening argument lists - #250

Merged
huandu merged 2 commits into
huandu:masterfrom
yuefdev:fix/flatten-nil-values-sol
Oct 21, 2026
Merged

huandu merged 2 commits into
huandu:masterfrom
yuefdev:fix/flatten-nil-values-sol

Conversation

@yuefdev

@yuefdev yuefdev commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Preserve nil scalar elements in Flatten and List. List([]interface{}{1, nil, 2}) currently produces two placeholders and drops the SQL NULL argument, while an untyped nil input also contradicts Flatten's scalar contract.

Represent a nil leaf as one flattened element while continuing to omit empty slices. The regression fails before the fix; full tests, vet and changed-file gofmt pass.

@huandu huandu added the bug label Oct 20, 2026
@coveralls

coveralls commented Oct 20, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 96.173% (+0.003%) from 96.17% — yuefdev:fix/flatten-nil-values-sol into huandu:master

@huandu huandu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

One small test-style suggestion; the Flatten fix itself looks correct.

Comment thread flatten_nil_test.go Outdated
{[]interface{}{1, nil, []interface{}{nil, 2}}, []interface{}{1, nil, nil, 2}},
{[]interface{}{[]int{}, []int(nil)}, nil},
} {
if got := Flatten(tc.input); !reflect.DeepEqual(got, tc.want) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Small consistency suggestion: the existing tests in this package use github.com/huandu/go-assert (for example, TestFlatten in modifiers_test.go), while this new test uses reflect.DeepEqual here and again on line 22. Could we switch these assertions to go-assert and drop the reflect import? Functionally this is fine; it just keeps the test suite consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've switched these to go-assert and dropped the reflect import in f85bd2e. The nil values and SQL arguments are still covered, using the same assertion style as TestFlatten. go test ./... passes.

@huandu
huandu merged commit c20cbdf into huandu:master Oct 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants