diff --git a/CHANGELOG b/CHANGELOG index bca327db8e..9d9236bb0b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add check on ModelSQL for positive id * New API to read related fields * Remove implicit fields names in ModelStorage.read * Check read access on field in search domain (issue7766) diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 0b7c3fbfd1..2e675ef7ca 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -160,15 +160,6 @@ class ModelSQL(ModelStorage): @classmethod def __setup__(cls): - super(ModelSQL, cls).__setup__() - cls._sql_constraints = [] - cls._order = [('id', 'ASC')] - cls._sql_error_messages = {} - if issubclass(cls, ModelView): - cls.__rpc__.update({ - 'history_revisions': RPC(), - }) - cls._table = config.get('table', cls.__name__, default=cls._table) if not cls._table: cls._table = cls.__name__.replace('.', '_') @@ -176,6 +167,21 @@ class ModelSQL(ModelStorage): assert cls._table[-9:] != '__history', \ 'Model _table %s cannot end with "__history"' % cls._table + super(ModelSQL, cls).__setup__() + + cls._sql_constraints = [] + if not callable(cls.table_query): + table = cls.__table__() + cls._sql_constraints.append( + ('id_positive', Check(table, table.id >= 0), + "ID must be positive")) + cls._order = [('id', 'ASC')] + cls._sql_error_messages = {} + if issubclass(cls, ModelView): + cls.__rpc__.update({ + 'history_revisions': RPC(), + }) + @classmethod def __table__(cls): if callable(cls.table_query):