fix: add Conn and *Conn to mapperFor and isUnsafe type switches#992
Open
xbrxr03 wants to merge 1 commit into
Open
fix: add Conn and *Conn to mapperFor and isUnsafe type switches#992xbrxr03 wants to merge 1 commit into
xbrxr03 wants to merge 1 commit into
Conversation
mapperFor() and isUnsafe() only handled DB, *DB, Tx, and *Tx types. When a Stmt was created from a *sqlx.Conn, both functions fell through to the default case — mapperFor returned the global mapper instead of the Conn's custom Mapper, and isUnsafe returned false instead of the Conn's unsafe flag. This meant that any custom Mapper configured on a Conn (e.g. via tagMapFunc) was silently dropped when creating prepared statements, causing field mapping to use the wrong mapper. Add Conn and *Conn to both type switches with tests. Fixes jmoiron#975
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
mapperFor()andisUnsafe()only handleDB,*DB,Tx, and*Txtypes in their type switches. When aStmtis created from a*sqlx.Conn, both functions fall through to the default case:mapperFor(conn)returns the global mapper instead ofconn.MapperisUnsafe(conn)returnsfalseinstead ofconn.unsafeThis silently drops any custom
Mapperconfigured on aConn(e.g. viatagMapFunc), causing field mapping to use the wrong mapper when creating prepared statements from a connection.Reported in #975.
Fix
Add
Connand*Connto both type switches:Tests
TestMapperForConn: verifiesmapperForreturns the correctMapperforConnand*Conn, including custom mapper instancesTestIsUnsafeConn: verifiesisUnsafereturns the correctunsafeflag forConnand*ConnFixes #975