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

Bug: various int arrays are generated as types.Int64Array which leads to out of range errors in tests #1308

Open
erezrokah opened this issue Sep 21, 2023 · 2 comments

Comments

@erezrokah
Copy link

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v4.15.0 (Actually I'm using the latest code from master)

What is your database and version (eg. Postgresql 10)

Postgres 15

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler psql --wipe --no-hooks --no-auto-timestamps --no-back-referencing

If this happened at runtime what code produced the issue? (if not applicable leave blank)

N/A

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

create table if not exists my_table(
    id serial primary key,
    small_ints smallint[]
);

Further information. What did you do, what did you expect?

Looks like various types of int arrays are always generated as types.Int64Array:

case "bigint", "bigserial", "integer", "serial", "smallint", "smallserial", "oid":
, which means when seeding the values with random data it can overflow the DB type

@erezrokah erezrokah changed the title Bug: various int arrays are generated as types.Int64Array which leads to our of range errors in tests Bug: various int arrays are generated as types.Int64Array which leads to out of range errors in tests Sep 21, 2023
@kylelmh
Copy link

kylelmh commented Aug 16, 2024

I am facing the same problem.
From the source code, looks like int32 arrays are not checked. I think it would be a matter of adding a []int check before the int64 check and a new IntArray type. But this could cause overflow if the int in question is int64, just not over 32 bits in value yet...

sqlboiler/types/array.go

Lines 462 to 487 in 8c10c06

func Array(a interface{}) interface {
driver.Valuer
sql.Scanner
} {
switch a := a.(type) {
case []bool:
return (*BoolArray)(&a)
case []float64:
return (*Float64Array)(&a)
case []int64:
return (*Int64Array)(&a)
case []string:
return (*StringArray)(&a)
case *[]bool:
return (*BoolArray)(a)
case *[]float64:
return (*Float64Array)(a)
case *[]int64:
return (*Int64Array)(a)
case *[]string:
return (*StringArray)(a)
}
return GenericArray{a}
}

I am working around this by manually modifying the generated files to match my schema definition, but this is hard to maintain. Maybe it would be useful to define overrides in the generation process?

@stephenafamo
Copy link
Collaborator

PR welcome 🙏🏾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants