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 missing error-check in AutoMigrate #5283

Merged
merged 1 commit into from Apr 22, 2022
Merged

Conversation

glebarez
Copy link
Contributor

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Error check was missing in AutoMigrate.
Due to this miss, errors of underlying drivers might not be delivered, resulting in misleading error texts.
Example of such behavior is showed in #5282, which is duplicate column name: id but real error was in SQLite driver, namely invalid ddl

User Case Description

@@ -99,7 +99,10 @@ func (m Migrator) AutoMigrate(values ...interface{}) error {
}
} else {
if err := m.RunWithValue(value, func(stmt *gorm.Statement) (errr error) {
columnTypes, _ := m.DB.Migrator().ColumnTypes(value)
columnTypes, err := m.DB.Migrator().ColumnTypes(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

this err is shadowing the previous one, you can remove the :

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the local error inside function literal scope, which returns error as well. Looks good to me.

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.

None yet

3 participants