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

Cherry pick fix for panic reflect.Value.Interface on zero value #397

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions gorm/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ func (converter *DefaultFilteringConditionConverter) StringConditionToGorm(ctx c
return converter.insensitiveCaseStringConditionToGorm(neg, dbName, o), []interface{}{value}, assocToJoin, nil
}

// N.B. if the user specifies a value that the codec translates to NULL
// (e.g. `field1 == ""` for string columns) instead of using the explicit
// support for identity (`field1 == null`), the results of this syntax may
// not match user expectations - `(col_name = NULL)` will match no rows,
// not even rows with NULL values. Did the user intend to match rows with
// NULL values (`field1 IS NULL`)?
return fmt.Sprintf("%s(%s %s ?)", neg, dbName, o), []interface{}{value}, assocToJoin, nil
}

Expand Down Expand Up @@ -226,6 +232,14 @@ func (p *DefaultFilteringConditionProcessor) ProcessStringCondition(ctx context.
if !ormId.IsValid() {
return nil, fmt.Errorf("Cannot find field %s in %s", part, objType)
}
// For type values where the codec translates a NULL value in
// SQL, we receive a pointer of nil value. E.g. `""`.
switch ormId.Kind() {
case reflect.Ptr, reflect.UnsafePointer:
if ormId.IsNil() {
return nil, nil
}
}
return reflect.Indirect(ormId).Interface(), nil

}
Expand Down
Loading