← Back to team overview

openerp-community team mailing list archive

lp:~openerp-community/openobject-server/stefan-therp_lp727727-6.1 into lp:openobject-server

 

Stefan Rijnhart (Therp) has proposed merging lp:~openerp-community/openobject-server/stefan-therp_lp727727-6.1 into lp:openobject-server.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #727727 in OpenERP Server: "Orm.create() should not drop nonexisting fields in passed values"
  https://bugs.launchpad.net/openobject-server/+bug/727727

For more details, see:
https://code.launchpad.net/~openerp-community/openobject-server/stefan-therp_lp727727-6.1/+merge/80904

This branch raises an exception when a value is passed to the ORM for a non existing field during create() or write(). Previously these values were simply dropped, which could lead to data loss.

-- 
https://code.launchpad.net/~openerp-community/openobject-server/stefan-therp_lp727727-6.1/+merge/80904
Your team OpenERP Community is subscribed to branch lp:~openerp-community/openobject-server/stefan-therp_lp727727-6.1.
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py	2011-10-19 11:46:18 +0000
+++ openerp/osv/orm.py	2011-11-01 14:06:37 +0000
@@ -3808,6 +3808,7 @@
             for id in ids:
                 result += self._columns[field].set(cr, self, id, field, vals[field], user, context=rel_context) or []
 
+        unknown_fields = updend[:]
         for table in self._inherits:
             col = self._inherits[table]
             nids = []
@@ -3820,9 +3821,16 @@
             for val in updend:
                 if self._inherit_fields[val][0] == table:
                     v[val] = vals[val]
+                    unknown_fields.remove(val)
             if v:
                 self.pool.get(table).write(cr, user, nids, v, context)
 
+        if unknown_fields:
+            raise except_orm(
+                _('ValidateError'),
+                _('No such field in model %s: %s.') %  (unknown_fields[0],
+                                                        self._name)
+                )
         self._validate(cr, user, ids, context)
 
         # TODO: use _order to set dest at the right position and not first node of parent
@@ -3952,7 +3960,10 @@
                 del vals[v]
             else:
                 if (v not in self._inherit_fields) and (v not in self._columns):
-                    del vals[v]
+                    raise except_orm(
+                        _('ValidateError'),
+                        _('No such field in model %s: %s.') % (self._name, v)
+                        )
 
         # Try-except added to filter the creation of those records whose filds are readonly.
         # Example : any dashboard which has all the fields readonly.(due to Views(database views))


Follow ups