Odoo14 - AttributeError: 'tuple' object has no attribute 'cache'" while evaluating

Odoo14 - AttributeError: 'tuple' object has no attribute 'cache'" while evaluating

我在 Odoo 中有一个模型来注册一些 logs(Log) 和一个具有异步功能的助手 class(Helper) 来接收一些数据广告在日志上注册,这个 _job_function 由 Cron 调用像这样的工作:

class Log(models.Model):
    _name = 'saas.autobackup'
    _description = 'Description'

    field1 = fields.Char()
    field2 = fields.Char()
    field3 = fields.Datetime()

  def _job_function(self):
     helper = Hekper(self, ...) #Function receive self(Log) as parameter
     helper.run()  #call functions

这是帮手class:

class Helper():
  def __init__(self, og_obj)
    self.log_obj = log_obj  #Receive the Log object as parameter
 
  async def some_async_func(self):
   (...) #Some async functions to get val1 and val2
   self.create_log(val1,val2)
      
  def create_log(self, val1, val2)
    vals = {'field1': val1, 'field2': val1, 'field3': '2021-01-01'}
    self.log_obj.create(values)

  def run(self):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    future = asyncio.ensure_future(self.some_async_func())
    loop.run_until_complete(future)

为了调试 propuser,我重写了创建 class,以检查我是否发送了错误的数据。 当执行作业调用create_log函数时,程序正确进入了create函数,我也检查了create中发送的数据,我验证它们是正确的,就像我尝试时保留的一样在 Odoo 界面本身中创建。 “创建”按钮。但是在 Odoo 中通过创建按钮,正常创建并通过 create_log 函数我得到这个错误:

ValueError: <class 'AttributeError'>: "'tuple' object has no attribute 'cache'" while evaluating

由于这是一个线程问题,您需要确保创建一个新游标。

    def create_log(self, val1, val2)
        vals = {'field1': val1, 'field2': val1, 'field3': '2021-01-01'}
        with api.Environment.manage():
            with registry(self.env.cr.dbname).cursor() as new_cr:
                new_env = api.Environment(new_cr, self.env.uid, self.env.context)
                self.with_env(new_env).log_obj.create(values)```