Skip to content

fix(expr): handle nil value-receiver Valuers - #406

Open
terminalchai wants to merge 1 commit into
Masterminds:masterfrom
terminalchai:fix/nil-driver-valuers
Open

terminalchai wants to merge 1 commit into
Masterminds:masterfrom
terminalchai:fix/nil-driver-valuers

Conversation

@terminalchai

Copy link
Copy Markdown

Passing a nil *sql.NullString or *sql.NullInt64 to a comparison currently panics when its value-receiver Value() method is invoked. For example, Eq{"name": (*sql.NullString)(nil)}.ToSql() should produce name IS NULL.

Use the same nil-Valuer distinction as database/sql: a nil pointer to a value type implementing driver.Valuer represents NULL, while custom pointer-receiver implementations still receive nil and can return their own value or error. Apply this to the three existing Valuer resolution paths. Eq/NotEq produce their existing NULL comparisons; LIKE and ordered comparisons return their existing NULL errors.

Adds 70 regression and compatibility cases across all ten operators. The 20 standard nil-pointer cases reproduce the panic before the fix. Full tests, race tests, Windows 386 tests, vet, build, and SQLite integration tests pass on Go 1.26.1. MySQL and PostgreSQL integration tests were not run locally. Existing documentation formatting was retained; changed production code and the new test file match gofmt.

Prepared with AI assistance and separate specification and code reviews.

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.

1 participant