Do not read deleted record as extra record
When a record from a browse list has been deleted, we must not try to read it if other records are accessed. issue10652 review346731080
This commit is contained in:
1 parent
6dd98fac4a
commit
a63de7ab07
2 files changed
+25
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in new issue
Block a user