Limit the start id of table to 500 for tests
By using the formula `(idx * prime) % range + 1`, tables created consecutively have start id distant by `prime` and the maximum start id is `range`. This avoid to overflow int4 when composing unique ID for table query. Closes #15010
This commit is contained in:
@@ -510,10 +510,12 @@ class ModelSQL(ModelStorage):
|
||||
table = cls.__table_handler__(module_name)
|
||||
if Pool.test:
|
||||
from trytond.tests import TABLES_CREATED
|
||||
range_ = 500
|
||||
prime = 101 # coprime of 500
|
||||
if cls._table not in TABLES_CREATED:
|
||||
database.setnextid(
|
||||
transaction.connection, cls._table,
|
||||
len(TABLES_CREATED) * 500 + 1)
|
||||
(len(TABLES_CREATED) * prime) % range_ + 1)
|
||||
TABLES_CREATED.add(cls._table)
|
||||
|
||||
if cls._history:
|
||||
@@ -524,7 +526,7 @@ class ModelSQL(ModelStorage):
|
||||
if table_history not in TABLES_CREATED:
|
||||
database.setnextid(
|
||||
transaction.connection, table_history,
|
||||
len(TABLES_CREATED) * 500 + 1)
|
||||
(len(TABLES_CREATED) * prime) % range_ + 1)
|
||||
TABLES_CREATED.add(table_history)
|
||||
|
||||
for field_name, field in cls._fields.items():
|
||||
|
||||
Reference in New Issue
Block a user