[FIX] models: make sure an environment is available when we access field.digits

Accessing `field.digits` can crash if no environment is available at that
point.  This happens in function `get_pg_type()`, which is called from method
`_auto_init()`.  An environment is simply created in the method's scope to be
available for `field.digits`.
This commit is contained in:
Raphael Collet 2015-05-05 15:03:06 +02:00
parent 071152216f
commit 0c665edb66
1 changed files with 5 additions and 0 deletions

View File

@ -2431,6 +2431,11 @@ class BaseModel(object):
# has not been added in database yet!
context = dict(context or {}, prefetch_fields=False)
# Make sure an environment is available for get_pg_type(). This is
# because we access column.digits, which retrieves a cursor from
# existing environments.
env = api.Environment(cr, SUPERUSER_ID, context)
store_compute = False
stored_fields = [] # new-style stored fields with compute
todo_end = []