Skip to content

uint64 equality and eager loading bug #399

Closed
@mickeyreiss

Description

@mickeyreiss

We are facing a strange issue where eager loads on nullable uint64 fields, such that eager loads of related models completely fail:

primitive type of a (int64) was not the same primitive type as b (uint64)

We have narrowed this down to a possible bug in null/int64.go:

// Value implements the driver Valuer interface.
func (u Uint64) Value() (driver.Value, error) {
	if !u.Valid {
		return nil, nil
	}
	return int64(u.Uint64), nil
}

We also dug into reflect.go and found some potentially suspect code. Apparently unsigned numbers are casted to signed numbers before == in upgradeNumericTypes. Maybe this is correct, but we didn't see an explicit comment around comparing unsigned and signed values.

Is it correct to cast the uint64 to an int64 here?

We use mysql bigint unsigned for our primary keys and foreign relations, and we are seeing this in a number of situations where we are eager loading a model with a bigint unsigned foreign key to the model being queried.

We tried the obvious thing..hacking the line above to uint64, but then other errors crop up. We presume that the bug is consistent in a number of places in the generated models.

P.S. Does the Value bug above lead to a underflow issues for negative numbers?

cc/ @jthreatt4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions