Skip to content

fix(Migrator): prevent nil pointer dereference in AlterColumn#339

Merged
jinzhu merged 1 commit into
go-gorm:masterfrom
lihan3238:fix-338
May 11, 2026
Merged

fix(Migrator): prevent nil pointer dereference in AlterColumn#339
jinzhu merged 1 commit into
go-gorm:masterfrom
lihan3238:fix-338

Conversation

@lihan3238
Copy link
Copy Markdown
Contributor

Closes #338

Summary

AlterColumn has two issues:

  1. Error from ColumnTypes() is discarded (assigned to _)
  2. fieldColumnType is dereferenced without nil check when the schema field DBName is not found in the column types result

When schema/DB drift occurs (e.g. concurrent DROP COLUMN, partially applied migration), this causes a nil pointer panic.

Fix

  • Propagate ColumnTypes() error instead of discarding it
  • Add nil guard for fieldColumnType with a descriptive error message

Test Plan

When a schema field DBName is absent from ColumnTypes() result
(e.g. schema/DB drift, concurrent DROP COLUMN), fieldColumnType
remains nil and causes a panic on subsequent method calls.

Also propagate the ColumnTypes() error instead of discarding it.

Closes go-gorm#338
@jinzhu jinzhu merged commit 65c4b89 into go-gorm:master May 11, 2026
1 check 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.

Bug: nil pointer dereference at migrator.go:336 in (Migrator).AlterColumn when schema field's DBName is absent from ColumnTypes() result

2 participants