diff --git a/CHANGELOG b/CHANGELOG index d87c3aeaf2..af28b20bcc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ * Allow to override ModelSQL._table * Allow to import backend from entry points * Add reversed operators to PYSON expressions +* Explicity raise error when creating/writing/deleting models with table_query * Use CURRENT_TIMESTAMP instead of now * Use Constraint instance in ModelSQL._sql_constraints * Only return default record if no domain supplied on ModelSingleton search diff --git a/doc/ref/models/models.rst b/doc/ref/models/models.rst index d72e6c6df6..f5bd445d52 100644 --- a/doc/ref/models/models.rst +++ b/doc/ref/models/models.rst @@ -424,6 +424,12 @@ Class methods: Could be overrided to use a custom SQL query instead of a table of the database. It should return a SQL FromItem. + .. warning:: + By default all CRUD operation will raise an error on models + implementing this method so the create, write and delete methods may + also been overriden if needed. + .. + .. classmethod:: ModelSQL.history_revisions(ids) Return a sorted list of all revisions for ids. The list is composed of diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 44b7db1ada..089de5a577 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -471,7 +471,7 @@ class ModelSQL(ModelStorage): super(ModelSQL, cls).create(vlist) if cls.table_query(): - return False + raise NotImplementedError('Can not create model with table_query') table = cls.__table__() modified_fields = set() @@ -841,7 +841,8 @@ class ModelSQL(ModelStorage): super(ModelSQL, cls).write(records, values, *args) if cls.table_query(): - return + raise NotImplementedError( + 'Can not write on model with table_query') table = cls.__table__() cls.__check_timestamp(all_ids) @@ -941,7 +942,7 @@ class ModelSQL(ModelStorage): return if cls.table_query(): - return + raise NotImplementedError('Can not delete model with table_query') table = cls.__table__() if transaction.delete and transaction.delete.get(cls.__name__):