如何解决Odoo14 - AttributeError: 'tuple' 对象在评估
我在 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 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,我覆盖了 create 类,以检查我是否发送了错误的数据。 当作业执行并调用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)```
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。