[IMP] raise exception when a DB request fetches ids it was not asked for
authorXavier Morel <xmo@openerp.com>
Mon, 7 Jul 2014 07:59:05 +0000 (09:59 +0200)
committerXavier Morel <xmo@openerp.com>
Mon, 7 Jul 2014 07:59:05 +0000 (09:59 +0200)
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

openerp/models.py

index 86d702e..9e28996 100644 (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)') % \