From 5a3a52e1640fe630c7e5c36c2cabb8b162b08b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Mon, 10 Aug 2026 14:51:04 +0200 Subject: [PATCH] Reset TABLES_CREATED when dropping the database when testing Closes #15002 (grafted from e9f2b42e96ebb4553ef153f1d778c5d1042b3891) --HG-- branch : 8.0 --- trytond/trytond/model/modelsql.py | 27 +++++++++++++++------------ trytond/trytond/tests/__init__.py | 2 ++ trytond/trytond/tests/test_tryton.py | 3 +++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/trytond/trytond/model/modelsql.py b/trytond/trytond/model/modelsql.py index 6c3a61e1cb..31524d4538 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -302,7 +302,6 @@ def apply_sorting(keywords): return lambda col: NullOrdering(Order(col)) -_TABLES_CREATED = set() _TABLE_QUERY_COLUMNS = { 'create_uid': Literal(0), 'create_date': CurrentTimestamp(), @@ -509,20 +508,24 @@ class ModelSQL(ModelStorage): # create/update table in the database table = cls.__table_handler__(module_name) - if Pool.test and cls._table not in _TABLES_CREATED: - database.setnextid( - transaction.connection, cls._table, - len(_TABLES_CREATED) * 500 + 1) - _TABLES_CREATED.add(cls._table) + if Pool.test: + from trytond.tests import TABLES_CREATED + if cls._table not in TABLES_CREATED: + database.setnextid( + transaction.connection, cls._table, + len(TABLES_CREATED) * 500 + 1) + TABLES_CREATED.add(cls._table) if cls._history: history_table = cls.__table_handler__(module_name, history=True) - table_history = f'{cls._table}__history' - if Pool.test and table_history not in _TABLES_CREATED: - database.setnextid( - transaction.connection, table_history, - len(_TABLES_CREATED) * 500 + 1) - _TABLES_CREATED.add(table_history) + if Pool.test: + from trytond.tests import TABLES_CREATED + table_history = f'{cls._table}__history' + if table_history not in TABLES_CREATED: + database.setnextid( + transaction.connection, table_history, + len(TABLES_CREATED) * 500 + 1) + TABLES_CREATED.add(table_history) for field_name, field in cls._fields.items(): if field_name == 'id': diff --git a/trytond/trytond/tests/__init__.py b/trytond/trytond/tests/__init__.py index 9d9c582389..335d626d55 100644 --- a/trytond/trytond/tests/__init__.py +++ b/trytond/trytond/tests/__init__.py @@ -6,6 +6,8 @@ try: except ImportError: from importlib.metadata import entry_points +TABLES_CREATED = set() + def register(): from . import ( diff --git a/trytond/trytond/tests/test_tryton.py b/trytond/trytond/tests/test_tryton.py index 9fa155aac3..90ddd37060 100644 --- a/trytond/trytond/tests/test_tryton.py +++ b/trytond/trytond/tests/test_tryton.py @@ -42,6 +42,8 @@ from trytond.transaction import Transaction, TransactionError from trytond.wizard import StateAction, StateView from trytond.wsgi import app +from . import TABLES_CREATED as _TABLES_CREATED + __all__ = [ 'CONTEXT', 'Client', @@ -1339,6 +1341,7 @@ def drop_db(name=DB_NAME): database.drop(transaction.connection, name) Pool.stop(name) Cache.drop(name) + _TABLES_CREATED.clear() def drop_create(name=DB_NAME, lang='en'):