diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 74840f0500..8d271bac8a 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -298,6 +298,10 @@ class ModelStorage(Model): # Increase transaction counter Transaction().counter += 1 + # Clean local cache + for record in records: + record._local_cache.pop(record.id, None) + # Clean transaction cache for cache in list(Transaction().cache.values()): for cache in (cache, list( @@ -1555,9 +1559,13 @@ class ModelStorage(Model): context_field = self._fields.get(context_field_name) ffields[context_field_name] = context_field + delete_records = self._transaction.delete_records.get( + self.__name__, set()) + def filter_(id_): return (id_ == self.id # Ensure the value is read - or (( + or (id_ not in delete_records + and ( id_ not in self._cache or name not in self._cache[id_]) and (id_ not in self._local_cache diff --git a/trytond/tests/test_modelstorage.py b/trytond/tests/test_modelstorage.py index ede4c2eb68..9a71f42a1b 100644 --- a/trytond/tests/test_modelstorage.py +++ b/trytond/tests/test_modelstorage.py @@ -5,7 +5,7 @@ import unittest from trytond.model import EvalEnvironment from trytond.model.exceptions import ( - RequiredValidationError, DomainValidationError) + RequiredValidationError, DomainValidationError, AccessError) from trytond.pool import Pool from trytond.transaction import Transaction from trytond.tests.test_tryton import activate_module, with_transaction @@ -73,6 +73,21 @@ class ModelStorageTestCase(unittest.TestCase): count = ModelStorage.search_count([('name', '=', 'Test 5')]) self.assertEqual(count, 1) + @with_transaction() + def test_browse_deleted(self): + "Test access record from browse list with deleted record" + pool = Pool() + ModelStorage = pool.get('test.modelstorage') + records = ModelStorage.create( + [{'name': 'Test %s' % i} for i in range(2)]) + + ModelStorage.delete(records[1:]) + ModelStorage.write(records[:1], {}) # clean cache + + records[0].name + with self.assertRaises(AccessError): + records[1].name + @with_transaction() def test_browse_context(self): 'Test context when browsing'