result: don't panic when affectedRows/insertIds are empty#1769
result: don't panic when affectedRows/insertIds are empty#1769c-tonneslan wants to merge 1 commit into
Conversation
Closes go-sql-driver#1733. mysqlResult.LastInsertId / RowsAffected indexed into their slices without checking length, so any code path that left the result slices empty (e.g. an error before the affected-rows packet) panicked the caller. Return 0, nil instead, which matches the database/sql.Result contract for 'no rows affected'. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR fixes a panic in ChangesEmpty result panic fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" 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. Comment |
|
|
||
| // Regression for #1733: indexing into an empty result slice used to panic. | ||
| func TestEmptyResult(t *testing.T) { | ||
| r := &mysqlResult{} |
There was a problem hiding this comment.
Please provide reproducible steps for users.
|
Honestly, I went hunting for a real user-level repro on master and I can't get there. Every path that returns a result goes through readResultSetHeaderPacket first, which appends to both slices before any error check, so by the time RowsAffected runs the slices are length >= 1. The #1733 report is on v1.8.0 and the stack doesn't show how the conn ended up with empty slices, so I can't put a faithful repro in the test. I'll close this and defer to you and @methane on whether the guard is worth adding without one. |
Closes #1733.
mysqlResult.LastInsertId/RowsAffectedindexed into their slices without checking length, so any code path that left the slices empty (e.g. an error before the affected-rows packet) panicked the caller. Return0, nilinstead, which matches thedatabase/sql.Resultcontract for "no rows affected".