Merge lp:~openerp-dev/openobject-server/trunk-check-ids-thu into lp:openobject-server

Proposed by Vo Minh Thu
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/trunk-check-ids-thu
Merge into: lp:openobject-server
Diff against target: 87 lines (+31/-9)
3 files modified
openerp/addons/base/res/res_users.py (+3/-0)
openerp/conf/deprecation.py (+21/-0)
openerp/osv/orm.py (+7/-9)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-check-ids-thu
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+162594@code.launchpad.net
To post a comment you must log in.
4827. By Vo Minh Thu

[MERGE] merged trunk.

Unmerged revisions

4827. By Vo Minh Thu

[MERGE] merged trunk.

4826. By Vo Minh Thu

[REF] orm: added a deprecation warning helper for IDs check.

4825. By Vo Minh Thu

[REF] orm: deprecation warning when passing a single ID to read().

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openerp/addons/base/res/res_users.py'
--- openerp/addons/base/res/res_users.py 2013-04-04 13:07:04 +0000
+++ openerp/addons/base/res/res_users.py 2013-05-06 13:13:33 +0000
@@ -256,6 +256,8 @@
256 SELF_READABLE_FIELDS = ['signature', 'company_id', 'login', 'email', 'name', 'image', 'image_medium', 'image_small', 'lang', 'tz', 'tz_offset', 'groups_id', 'partner_id', '__last_update']256 SELF_READABLE_FIELDS = ['signature', 'company_id', 'login', 'email', 'name', 'image', 'image_medium', 'image_small', 'lang', 'tz', 'tz_offset', 'groups_id', 'partner_id', '__last_update']
257257
258 def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):258 def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
259 openerp.conf.deprecation.check_single_id(self, 'read', ids, _logger)
260
259 def override_password(o):261 def override_password(o):
260 if 'password' in o and ('id' not in o or o['id'] != uid):262 if 'password' in o and ('id' not in o or o['id'] != uid):
261 o['password'] = '********'263 o['password'] = '********'
@@ -280,6 +282,7 @@
280 return result282 return result
281283
282 def write(self, cr, uid, ids, values, context=None):284 def write(self, cr, uid, ids, values, context=None):
285 openerp.conf.deprecation.check_single_id(self, 'write', ids, _logger)
283 if not hasattr(ids, '__iter__'):286 if not hasattr(ids, '__iter__'):
284 ids = [ids]287 ids = [ids]
285 if ids == [uid]:288 if ids == [uid]:
286289
=== modified file 'openerp/conf/deprecation.py'
--- openerp/conf/deprecation.py 2013-03-27 16:40:45 +0000
+++ openerp/conf/deprecation.py 2013-05-06 13:13:33 +0000
@@ -37,6 +37,27 @@
37# Change to False around 2013.02.37# Change to False around 2013.02.
38open_openerp_namespace = False38open_openerp_namespace = False
3939
40# If True the old behavior of allowing a single ID to the orm methods is kept
41# but a warning is dieplayed in the logs. Otherwise raise an exception.
42# Introduced around 2013.03.
43allow_single_id = True
44
45def check_single_id(model, method, ids, logger):
46 if isinstance(ids, (int, long)):
47 if allow_single_id:
48 logger.warning('Passing a single ID to %s.%s() is deprecated.\n%s', model._name, method, get_caller(up=3))
49 else:
50 raise TypeError, 'Cannot pass a single ID to %s.%s().' % (model._name, method)
51
52def get_caller(up=2):
53 import inspect
54 try:
55 frame,filename,line_number,function_name,lines,index=\
56 inspect.getouterframes(inspect.currentframe())[up]
57 return "Called in %s() at %s:%s." % (function_name, filename, line_number)
58 except Exception, e:
59 return "Called in an unknown location, probably inside a safe_eval()."
60
40# If True, openerp.netsvc.LocalService() can be used to lookup reports or to61# If True, openerp.netsvc.LocalService() can be used to lookup reports or to
41# access openerp.workflow.62# access openerp.workflow.
42# Introduced around 2013.03.63# Introduced around 2013.03.
4364
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py 2013-04-22 09:36:55 +0000
+++ openerp/osv/orm.py 2013-05-06 13:13:33 +0000
@@ -3599,16 +3599,13 @@
35993599
3600 self.check_access_rights(cr, user, 'read')3600 self.check_access_rights(cr, user, 'read')
3601 fields = self.check_field_access_rights(cr, user, 'read', fields)3601 fields = self.check_field_access_rights(cr, user, 'read', fields)
3602 if isinstance(ids, (int, long)):3602 openerp.conf.deprecation.check_single_id(self, 'read', ids, _logger)
3603 select = [ids]3603 if isinstance(ids, (int, long)):
3604 else:3604 result = self._read_flat(cr, user, [ids], fields, context, load)
3605 select = ids
3606 select = map(lambda x: isinstance(x, dict) and x['id'] or x, select)
3607 result = self._read_flat(cr, user, select, fields, context, load)
3608
3609 if isinstance(ids, (int, long)):
3610 return result and result[0] or False3605 return result and result[0] or False
3611 return result3606 else:
3607 result = self._read_flat(cr, user, ids, fields, context, load)
3608 return result
36123609
3613 def _read_flat(self, cr, user, ids, fields_to_read, context=None, load='_classic_read'):3610 def _read_flat(self, cr, user, ids, fields_to_read, context=None, load='_classic_read'):
3614 if not context:3611 if not context:
@@ -4105,6 +4102,7 @@
41054102
4106 if not context:4103 if not context:
4107 context = {}4104 context = {}
4105 openerp.conf.deprecation.check_single_id(self, 'write', ids, _logger)
4108 if not ids:4106 if not ids:
4109 return True4107 return True
4110 if isinstance(ids, (int, long)):4108 if isinstance(ids, (int, long)):