details: https://code.tryton.org/tryton/commit/5f9acc7045a8
branch: 7.4
user: Cédric Krier <[email protected]>
date: Sat Dec 13 14:33:42 2025 +0100
description:
Use the right primary column name for PostgreSQL database method
On history table the primary column is `__id` instead of `id`.
(grafted from a268eb84245222f554f16b0cdc0e0b065b647724)
diffstat:
trytond/trytond/backend/postgresql/database.py | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diffs (39 lines):
diff -r a4b4a3750b9b -r 5f9acc7045a8
trytond/trytond/backend/postgresql/database.py
--- a/trytond/trytond/backend/postgresql/database.py Sat Dec 13 12:56:46
2025 +0100
+++ b/trytond/trytond/backend/postgresql/database.py Sat Dec 13 14:33:42
2025 +0100
@@ -435,27 +435,32 @@
return True
def nextid(self, connection, table, count=1):
+ column = 'id' if not table.endswith('__history') else '__id'
cursor = connection.cursor()
cursor.execute(
"SELECT nextval(pg_get_serial_sequence(format(%s, %s), %s)) "
"FROM generate_series(1, %s)",
- ('%I', table, 'id', count))
+ ('%I', table, column, count))
if count == 1:
return cursor.fetchone()[0]
else:
return [id for id, in cursor]
def setnextid(self, connection, table, value):
+ if self.currid(connection, table) >= value:
+ return
+ column = 'id' if not table.endswith('__history') else '__id'
cursor = connection.cursor()
cursor.execute(
"SELECT setval(pg_get_serial_sequence(format(%s, %s), %s), %s)",
- ('%I', table, 'id', value))
+ ('%I', table, column, value))
def currid(self, connection, table):
+ column = 'id' if not table.endswith('__history') else '__id'
cursor = connection.cursor()
cursor.execute(
"SELECT pg_get_serial_sequence(format(%s, %s), %s)",
- ('%I', table, 'id'))
+ ('%I', table, column))
sequence_name, = cursor.fetchone()
cursor.execute(f"SELECT last_value FROM {sequence_name}")
return cursor.fetchone()[0]