From 53fe643e61e942ba384d09bbc45dc7e874b1f731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 17 Aug 2026 15:06:09 +0200 Subject: [PATCH] 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 --- trytond/trytond/model/modelsql.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/trytond/trytond/model/modelsql.py b/trytond/trytond/model/modelsql.py index 1f4b9848e3..29153bd1b6 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -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():