首页 > 其他分享 >odoo CacheMiss 错误

odoo CacheMiss 错误

时间:2022-12-31 01:44:05浏览次数:65  
标签:compute 错误 self cache CacheMiss record ._ odoo recs

在进行调拨时遇到错误, stock.quant(12345,).product_uom_id
然后没有其他任何提示, 这种错误就比较难定位,到处打断点才定位到错误的位置,
odoo针对计算字段compute,related,为了提高读取速度,有做预处理,但是不知道为什么就这一条记录做了预处理就报错了

https://www.odoo.com/documentation/12.0/developer/reference/orm.html?highlight=prefetch#record-cache-and-prefetching

解决办法:
不要让他做预处理了,直接在product_uom_id 字段中添加store=Ture 属性.

    def determine_value(self, record):
        """ Determine the value of ``self`` for ``record``. """
        env = record.env
        if record.id==32045:
            _logger.info('record:{},self{},self.store:{},self.compute:{},recursive:{}'.format(
                record,self,self.store,self.compute,self.recursive))

        if self.store and not (self.compute and env.in_onchange):
            # this is a stored field or an old-style function field
            if self.compute:
                # this is a stored computed field, check for recomputation
                recs = record._recompute_check(self)
                if recs:
                    # recompute the value (only in cache)
                    if self.recursive:
                        recs = record
                    self.compute_value(recs)
                    # HACK: if result is in the wrong cache, copy values
                    if recs.env != env:
                        computed = record._field_computed[self]
                        for source, target in pycompat.izip(recs, recs.with_env(env)):
                            try:
                                values = {f.name: source[f.name] for f in computed}
                                target._cache.update(target._convert_to_cache(values, validate=False))
                            except MissingError as exc:
                                target._cache.set_failed(target._fields, exc)
                    # the result is saved to database by BaseModel.recompute()
                    return

            # read the field from database
            record._prefetch_field(self)

        elif self.compute:
            # this is either a non-stored computed field, or a stored computed
            # field in onchange mode
            if self.recursive:
                self.compute_value(record)
            else:

                recs = record._in_cache_without(self)
                if record.id == 32045:
                    _logger.info('recs:{},name:{}'.format(recs,recs.mapped('product_id.name')))
                recs = recs.with_prefetch(record._prefetch)
                self.compute_value(recs)
                if record.id == 32045:
                    _logger.info('recs:{}'.format(recs))

        else:
            # this is a non-stored non-computed field
            record.env.cache.set(record, self, self.convert_to_cache(False, record, validate=False))

标签:compute,错误,self,cache,CacheMiss,record,._,odoo,recs
From: https://www.cnblogs.com/qianxunman/p/17016163.html

相关文章