From 33856ac2a19cba1efcb483d77cd3ef8133713b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 14 Mar 2026 18:12:02 +0100 Subject: [PATCH] Add model attribute to table handler --- trytond/doc/ref/backend.rst | 4 ++++ trytond/trytond/backend/postgresql/table.py | 3 +-- trytond/trytond/backend/sqlite/table.py | 5 ++--- trytond/trytond/backend/table.py | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/trytond/doc/ref/backend.rst b/trytond/doc/ref/backend.rst index b72f5ed843..2ffadf356c 100644 --- a/trytond/doc/ref/backend.rst +++ b/trytond/doc/ref/backend.rst @@ -253,6 +253,10 @@ TableHandler Handle table for the ``model``. If ``history`` is set, the table is the one storing the history. +.. attribute:: TableHandler.model + + The :class:`~trytond.model.ModelSQL` of the handled table. + .. attribute:: TableHandler.history A boolean to handle the history table. diff --git a/trytond/trytond/backend/postgresql/table.py b/trytond/trytond/backend/postgresql/table.py index 00f215e810..c69f700d82 100644 --- a/trytond/trytond/backend/postgresql/table.py +++ b/trytond/trytond/backend/postgresql/table.py @@ -28,7 +28,6 @@ class TableHandler(TableHandlerInterface): self.__constraints = None self.__fk_deltypes = None self.__indexes = None - self._model = model transaction = Transaction() cursor = transaction.connection.cursor() @@ -188,7 +187,7 @@ class TableHandler(TableHandlerInterface): if not self.history: history_table = self.table_name + '__history' if self.__class__.table_exist(history_table): - history_h = self.__class__(self._model, True) + history_h = self.__class__(self.model, True) history_h.column_rename(old_name, new_name) else: logger.warning( diff --git a/trytond/trytond/backend/sqlite/table.py b/trytond/trytond/backend/sqlite/table.py index 308227a93b..816569f0f4 100644 --- a/trytond/trytond/backend/sqlite/table.py +++ b/trytond/trytond/backend/sqlite/table.py @@ -29,7 +29,6 @@ class TableHandler(TableHandlerInterface): super()._init(model, history=history) self.__columns = None self.__indexes = None - self._model = model cursor = Transaction().connection.cursor() # Create new table if necessary @@ -90,7 +89,7 @@ class TableHandler(TableHandlerInterface): temp_table = '__temp_%s' % self.table_name temp_columns = dict(self._columns) self.table_rename(self.table_name, temp_table) - self._init(self._model, history=self.history) + self._init(self.model, history=self.history) columns, old_columns = [], [] for name, values in temp_columns.items(): if name in drop_columns: @@ -125,7 +124,7 @@ class TableHandler(TableHandlerInterface): if not self.history: history_table = self.table_name + '__history' if self.__class__.table_exist(history_table): - history_h = self.__class__(self._model, True) + history_h = self.__class__(self.model, True) history_h.column_rename(old_name, new_name) else: logger.warning( diff --git a/trytond/trytond/backend/table.py b/trytond/trytond/backend/table.py index 0948569384..048478a8e7 100644 --- a/trytond/trytond/backend/table.py +++ b/trytond/trytond/backend/table.py @@ -34,7 +34,7 @@ class TableHandlerInterface(object): self.table_name = model._table + '__history' else: self.table_name = model._table - self.object_name = model.__name__ + self.model = model if history: self.sequence_name = self.table_name + '___id_seq' else: