Skip to content

Conversation

@brandur
Copy link
Contributor

@brandur brandur commented Dec 30, 2025

The migration functions are supposed to allow you to call them with
nil options, but I noticed in some cases it's not working properly for
MigrateTx and it's possible to raise a nil pointer panic.

Here, initialize a nil opts earlier to prevent the problem. This makes
the code more obvious/conventional anyway in that it's easier to see
that nil options is supposed to be supported.

@brandur brandur force-pushed the brandur-zero-opts-early branch from 1b99a6e to 2cb7e3d Compare December 30, 2025 19:21
@brandur brandur requested a review from bgentry December 30, 2025 19:27
func (m *Migrator[TTx]) MigrateTx(ctx context.Context, tx TTx, direction Direction, opts *MigrateOpts) (*MigrateResult, error) {
if opts == nil {
opts = &MigrateOpts{}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively these could be right at the beginning of migrateUp and migrateDown, but I figure the earlier the better and other places in the code we have that do this tend to come right away.

Copy link
Contributor

@bgentry bgentry left a comment

Choose a reason for hiding this comment

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

I think I slightly prefer the alternative of putting these guards at the start of migrateUp / migrateDown since the caller is so thin, but either way is ok. Good fix!

The migration functions are supposed to allow you to call them with
nil options, but I noticed in some cases it's not working properly for
`MigrateTx` and it's possible to raise a nil pointer panic.

Here, initialize a nil `opts` earlier to prevent the problem. This makes
the code more obvious/conventional anyway in that it's easier to see
that nil options is supposed to be supported.
@brandur brandur force-pushed the brandur-zero-opts-early branch from 2cb7e3d to 71e1fab Compare December 31, 2025 00:09
@brandur brandur merged commit df1aa83 into master Dec 31, 2025
14 checks passed
@brandur brandur deleted the brandur-zero-opts-early branch December 31, 2025 05:51
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.

3 participants