Community: Framework mailing list archives

expert-framework@mail.odoo.com

Re: How to get a new cursor on new api on Thread

by
Suzanne Jean-Sébastien
- 09/22/2014 10:08:17


2014-09-22 16:07 GMT+02:00 Jean-Sébastien Suzanne <jssuzanne@anybox.fr>:
Hi Maxim,

try this

context = self.env.context

 self.env.cr.dbname 

cursor = sql_db.db_connect(dbname).cursor()

uid = self.user.id

with api.Environment.manage():

    env = api.Environment(cursor, uid, context)


Il wrote this code in a cron, and it work.

2014-09-22 11:37 GMT+02:00 Maxim Litnitskiy <litnimaxster@gmail.com>:
with Environment.manage():  # class function
    env = Environement(cr, uid, context)

Tried this code:

    def run_dialer(self, dialer_id):
        with Environment.manage():
            cr, uid, context = self.env.args
            env = Environment(cr, uid, context)
            dialer = env['asterisk.dialer'].browse([dialer_id])
            domain = [('phone', '!=', None)] + [eval(dialer.dialer_domain)[0]]
            contacts = env[dialer.dialer_model].search(domain)

The same:
Exception in thread Thread-7:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 808, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 761, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/max/tmp-work/odoo/odoo.my/openerp/api.py", line 235, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/max/tmp-work/odoo/myaddons/asterisk_dialer/models/dialer.py", line 98, in run_dialer
    contacts = env[dialer.dialer_model].search(domain)
  File "/home/max/tmp-work/odoo/odoo.my/openerp/api.py", line 235, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/max/tmp-work/odoo/odoo.my/openerp/api.py", line 464, in new_api
    result = method(self._model, cr, uid, *args, **kwargs)
  File "/home/max/tmp-work/odoo/odoo.my/openerp/models.py", line 1679, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/home/max/tmp-work/odoo/odoo.my/openerp/api.py", line 237, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/max/tmp-work/odoo/odoo.my/openerp/addons/base/res/res_partner.py", line 643, in _search
    count=count, access_rights_uid=access_rights_uid)
  File "/home/max/tmp-work/odoo/odoo.my/openerp/api.py", line 237, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/max/tmp-work/odoo/odoo.my/openerp/models.py", line 4543, in _search
    res = cr.fetchall()
  File "/home/max/tmp-work/odoo/odoo.my/openerp/sql_db.py", line 157, in wrapper
    raise psycopg2.OperationalError(msg)
OperationalError: Unable to use a closed cursor.

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-framework-62
Post to: mailto:expert-framework@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--
Jean-Sébastien SUZANNE
jssuzanne@anybox.fr
06 51 35 50 50



--
Jean-Sébastien SUZANNE
jssuzanne@anybox.fr
06 51 35 50 50