[IMP] raise exception when a DB request fetches ids it was not asked for

Likely caused by a type incoherence e.g. providing an id as string when the
table uses integer ids. Postgres performs an implicit conversion from string
to integer[0], this wasn't much of an issue in the old API, whatever cache was
there would simply not be used, but because the new API's cache is part of its
behavior it has a semantic impact and can lead to infinite recursion.

[0] more precisely from quoted value, which is untyped
This commit is contained in:
Xavier Morel 2014-07-07 09:59:05 +02:00
parent 74de2461a1
commit 798ce97df4
1 changed files with 9 additions and 1 deletions

View File

@ -3231,8 +3231,16 @@ class BaseModel(object):
record._cache.update(record._convert_to_cache(vals))
# store failed values in cache for the records that could not be read
missing = self - self.browse(ids)
fetched = self.browse(ids)
missing = self - fetched
if missing:
extras = fetched - self
if extras:
raise AccessError(
_("Database fetch misses ids ({}) and has extra ids ({}), may be caused by a type incoherence in a previous request").format(
', '.join(map(repr, missing._ids)),
', '.join(map(repr, extras._ids)),
))
# store an access error exception in existing records
exc = AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % \