Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
11299 Lượt xem

Hi

I'm developing a module importing data into a thread,Following this line I have an exception :

Unable to use a closed cursor

self.env['product.product'].search([('default_code', '=', internalRef)])

but if i don't use thread I have no exception

thanks a lot


Ảnh đại diện
Huỷ bỏ

Please show us some more of the code, it looks like the problem is on another line? :)

Câu trả lời hay nhất

Hi Merien Hakkani

In Odoo database cursor are opened at the beginning of the request and closed after the request is processed so it means that if you are using a new thread the cursor could or couldn't remain open when you wanna use it, normally it wont be open, so you may need to create a new env for self.env  with a new cursor attached in order to make it always work

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Hi Axel Mendoza

thank you very much for you answer , i tried this 

api.Environment.manage()

new_cr = registry(self._cr.dbname).cursor()

new_cr.autocommit(True)

self = self.with_env(self.env(cr=new_cr)).with_context(original_cr=self._cr)


Ảnh đại diện
Huỷ bỏ