Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sql.NullString mistaken as custom struct #1019

Merged
merged 1 commit into from
Oct 26, 2024

Conversation

CL-Jeremy
Copy link
Contributor

Tested with this concise official example with connection setup changed to PostgreSQL:

func main() {
ctx := context.Background()
sqldb, err := sql.Open(sqliteshim.ShimName, "file::memory:?cache=shared")
if err != nil {
panic(err)
}
sqldb.SetMaxOpenConns(1)
db := bun.NewDB(sqldb, sqlitedialect.New())
db.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
// Register models before loading fixtures.
db.RegisterModel((*User)(nil), (*Org)(nil))
// Automatically create tables.
fixture := dbfixture.New(db, dbfixture.WithRecreateTables())
// Load fixtures.
if err := fixture.Load(ctx, os.DirFS("."), "fixture.yml"); err != nil {
panic(err)
}

Without this fix, sql.NullString gets treated as a custom struct and then mapped to JSONB, resulting in failed insertion operations after the table has been created.

(Also removed currently unused, extraneous types.)

@CL-Jeremy
Copy link
Contributor Author

Of course, there could be more tests added to avoid this type of mistakes systematically. Just a bit unsure where to put such tests (for PGSQL specifically, or should there be a general, complicated test, e. g. loading fixtures, enabled for all backends?)

@vmihailenco vmihailenco merged commit 87c77b8 into uptrace:master Oct 26, 2024
3 of 4 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.

2 participants