except except_osv, inst:
self.abortResponse(1, inst.name, inst.exc_type, inst.value)
except IntegrityError, inst:
- for key in self._sql_error.keys():
+ osv_pool = pooler.get_pool(dbname)
+ for key in osv_pool._sql_error.keys():
if key in inst[0]:
self.abortResponse(1, _('Constraint Error'), 'warning',
- tr(self._sql_error[key], 'sql_constraint') or inst[0])
+ tr(osv_pool._sql_error[key], 'sql_constraint') or inst[0])
if inst.pgcode in (errorcodes.NOT_NULL_VIOLATION, errorcodes.FOREIGN_KEY_VIOLATION, errorcodes.RESTRICT_VIOLATION):
msg = _('The operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set')
self.logger.debug("IntegrityError", exc_info=True)
last_quote_end = errortxt.rfind('"')
last_quote_begin = errortxt.rfind('"', 0, last_quote_end)
model_name = table = errortxt[last_quote_begin+1:last_quote_end].strip()
- print "MODEL", last_quote_begin, last_quote_end, model_name
model = table.replace("_",".")
- model_obj = self.get(model)
+ model_obj = osv_pool.get(model)
if model_obj:
model_name = model_obj._description or model_obj._name
msg += _('\n\n[object with reference: %s - %s]') % (model_name, model)
nattr = {}
for s in ('_columns', '_defaults'):
new = copy.copy(getattr(pool.get(parent_name), s))
+ if s == '_columns':
+ # Don't _inherit custom fields.
+ for c in new.keys():
+ if new[c].manual:
+ del new[c]
+ # Duplicate float fields because they have a .digits
+ # cache (which must be per-pool, not server-wide).
+ for c in new.keys():
+ if new[c]._type == 'float':
+ new[c] = copy.copy(new[c])
if hasattr(new, 'update'):
new.update(cls.__dict__.get(s, {}))
else:
new.extend(cls.__dict__.get(s, []))
nattr[s] = new
cls = type(name, (cls, parent_class), nattr)
+ else:
+ # Duplicate float fields because they have a .digits
+ # cache (which must be per-pool, not server-wide).
+ for field_name, field in cls._columns.items():
+ if field._type == 'float':
+ cls._columns[field_name] = copy.copy(field)
obj = object.__new__(cls)
obj.__init__(pool, cr)
nattr = {}
for s in ('_columns', '_defaults', '_inherits', '_constraints', '_sql_constraints'):
new = copy.copy(getattr(pool.get(parent_name), s))
+ if s == '_columns':
+ # Don't _inherit custom fields.
+ for c in new.keys():
+ if new[c].manual:
+ del new[c]
+ # Duplicate float fields because they have a .digits
+ # cache (which must be per-pool, not server-wide).
+ for c in new.keys():
+ if new[c]._type == 'float':
+ new[c] = copy.copy(new[c])
+
if hasattr(new, 'update'):
new.update(cls.__dict__.get(s, {}))
else:
exist = False
for c2 in range(len(new)):
#For _constraints, we should check field and methods as well
- if new[c2][2]==c[2] and new[c2][0]==c[0]:
+ if new[c2][2]==c[2] and (new[c2][0] == c[0] \
+ or getattr(new[c2][0],'__name__', True) == \
+ getattr(c[0],'__name__', False)):
+ # If new class defines a constraint with
+ # same function name, we let it override
+ # the old one.
new[c2] = c
exist = True
break
new.extend(cls.__dict__.get(s, []))
nattr[s] = new
cls = type(name, (cls, parent_class), nattr)
+ else:
+ # Duplicate float fields because they have a .digits
+ # cache (which must be per-pool, not server-wide).
+ for field_name, field in cls._columns.items():
+ if field._type == 'float':
+ cls._columns[field_name] = copy.copy(field)
obj = object.__new__(cls)
obj.__init__(pool, cr)
return obj