details:   https://code.tryton.org/tryton/commit/887257d0aaf2
branch:    default
user:      Cédric Krier <[email protected]>
date:      Sat Mar 14 18:12:02 2026 +0100
description:
        Add model attribute to table handler
diffstat:

 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(-)

diffs (75 lines):

diff -r 18832c8b6d20 -r 887257d0aaf2 trytond/doc/ref/backend.rst
--- a/trytond/doc/ref/backend.rst       Sat Mar 14 18:11:34 2026 +0100
+++ b/trytond/doc/ref/backend.rst       Sat Mar 14 18:12:02 2026 +0100
@@ -253,6 +253,10 @@
    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 -r 18832c8b6d20 -r 887257d0aaf2 trytond/trytond/backend/postgresql/table.py
--- a/trytond/trytond/backend/postgresql/table.py       Sat Mar 14 18:11:34 
2026 +0100
+++ b/trytond/trytond/backend/postgresql/table.py       Sat Mar 14 18:12:02 
2026 +0100
@@ -28,7 +28,6 @@
         self.__constraints = None
         self.__fk_deltypes = None
         self.__indexes = None
-        self._model = model
 
         transaction = Transaction()
         cursor = transaction.connection.cursor()
@@ -188,7 +187,7 @@
                 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 -r 18832c8b6d20 -r 887257d0aaf2 trytond/trytond/backend/sqlite/table.py
--- a/trytond/trytond/backend/sqlite/table.py   Sat Mar 14 18:11:34 2026 +0100
+++ b/trytond/trytond/backend/sqlite/table.py   Sat Mar 14 18:12:02 2026 +0100
@@ -29,7 +29,6 @@
         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 @@
         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 @@
                 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 -r 18832c8b6d20 -r 887257d0aaf2 trytond/trytond/backend/table.py
--- a/trytond/trytond/backend/table.py  Sat Mar 14 18:11:34 2026 +0100
+++ b/trytond/trytond/backend/table.py  Sat Mar 14 18:12:02 2026 +0100
@@ -34,7 +34,7 @@
             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:

Reply via email to