From 7a3960f736436bb395e237153207c54214aa8dd2 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 9 Sep 2011 17:23:07 +0200 Subject: [PATCH] [IMP] remove size inference for selection lists with str|unicode value choices, simplify selection pg_type selection * if the first element of the choices list is an integer, use int4 * if the field has a size, use that size * else use an unrestricted varchar bzr revid: xmo@openerp.com-20110909152307-ralzt1g8l1b3e46x --- openerp/osv/orm.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 97c4ef89c60..2892a32c440 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -518,18 +518,10 @@ def get_pg_type(f, type_override=None): elif isinstance(f, (fields.char, fields.reference)): f_type = ('varchar', pg_varchar(f.size)) elif isinstance(f, fields.selection): - if isinstance(f.selection, list) and isinstance(f.selection[0][0], (str, unicode)): - f_size = reduce(lambda x, y: max(x, len(y[0])), f.selection, f.size) - elif isinstance(f.selection, list) and isinstance(f.selection[0][0], int): - f_size = -1 - else: - f_size = getattr(f, 'size', None) - - if f_size == -1: + if isinstance(f.selection, list) and isinstance(f.selection[0][0], int): f_type = ('int4', 'INTEGER') else: - f_type = ('varchar', pg_varchar(f_size)) - + f_type = ('varchar', pg_varchar(getattr(f, 'size', None))) elif isinstance(f, fields.function): if f._type = 'selection': f_type = ('varchar', pg_varchar())