From 8ac7724a67d878db2f8cc7ab94f1b247818052f9 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 18 Aug 2011 14:05:50 +0200 Subject: [PATCH] [IMP] fields.function: don't wrap int values unless really needed There was no need to wrap/cast int values for values less than 2^31-1, which the highest XML-RPC int value. Also, instead of wrapping them in strings, we can use float values, which are 64bits based in the XMLRPC standard, and closer to the real value (for comparisons, etc.). Added note for integer_big, as a reminder of this possible issue. bzr revid: qdp-launchpad@openerp.com-20110818120550-ulvffm6ka9f3c5ym --- openerp/osv/fields.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 056198a76d7..782cc8e796a 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -145,6 +145,14 @@ class integer(_column): _symbol_get = lambda self,x: x or 0 class integer_big(_column): + """Experimental 64 bit integer column type, currently unused. + + TODO: this field should work fine for values up + to 32 bits, but greater values will not fit + in the XML-RPC int type, so a specific + get() method is needed to pass them as floats, + like what we do for integer functional fields. + """ _type = 'integer_big' # do not reference the _symbol_* of integer class, as that would possibly # unbind the lambda functions @@ -1026,8 +1034,13 @@ class function(_column): else: result = sanitize_binary_value(value) - if field_type == "integer": - result = tools.ustr(value) + if field_type in ("integer","integer_big") and value > xmlrpclib.MAXINT: + # integer/long values greater than 2^31-1 are not supported + # in pure XMLRPC, so we have to pass them as floats :-( + # This is not needed for stored fields and non-functional integer + # fields, as their values are constrained by the database backend + # to the same 32bits signed int limit. + result = float(value) return result def get(self, cr, obj, ids, name, uid=False, context=None, values=None):