From ac845819eed7a70094b02ce157245f9de1b73358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csaba=20T=C3=B3th?= Date: Mon, 2 Feb 2015 10:51:05 +0100 Subject: [PATCH] [FIX] models: allow empty selection list If a selection field is created with an empty list of choices (e.g. added by submodules), initialise the field as a varchar column (most common). Check if the list exists to avoid crashing while checking the type of the first key. Fixes #3810 --- openerp/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/models.py b/openerp/models.py index e7e803f2608..9529c3e1e5e 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -190,7 +190,7 @@ def get_pg_type(f, type_override=None): elif issubclass(field_type, (fields.char, fields.reference)): pg_type = ('varchar', pg_varchar(f.size)) elif issubclass(field_type, fields.selection): - if (isinstance(f.selection, list) and isinstance(f.selection[0][0], int))\ + if (f.selection and isinstance(f.selection, list) and isinstance(f.selection[0][0], int))\ or getattr(f, 'size', None) == -1: pg_type = ('int4', 'INTEGER') else: