Skip to content
Advertisement

SQLAlchemy changes value after commit

Seemingly out of nowhere, my Flask app is now inserting the same value for one column in a table in my database no matter what when it had been previously working.

I have a model here:

JavaScript

and code in my application:

JavaScript

The result of the prints is

JavaScript

So it looks like after the record is committed, the number changes and it is always to this same number. I’ve never seen a problem like this and can’t figure out what is happening.

Advertisement

Answer

The problem is with the range of your value and the type of the column to which the value is being saved in.

The rma_number column has a SQLAlchemy column type of Integer but the value you are passing in (which is 2203193857 in this example) is greater than the maximum value of an Integer. As a result, it default to the maximum value it can store 2147483647 (i.e.: 2^31 – 1)

Consider using the BigInteger Column type instead, which allows for larger numbers. For more SQLAlchemy column types see https://docs.sqlalchemy.org/en/14/core/type_basics.html

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement