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/25/2014 15:15:41


2014-09-25 20:33 GMT+02:00 Maxim Litnitskiy <litnimaxster@gmail.com>:
The following seem to work reliably:

            new_cr = sql_db.db_connect(self.env.cr.dbname).cursor()
            uid, context = self.env.uid, self.env.context
            with api.Environment.manage():
                self.env = api.Environment(new_cr, uid, context)
For me is wrong, you don't change self.env

see the doc of Nicolas Bessi: https://github.com/nbessi/odoo_new_api_guideline 

                try:
                      ....

                finally:
                    self.env.cr.close()
 

FInally assures that cursor is closed on thready error or exit.

Thanks for advises.

P.S. May be this link can tell more if you are interested - https://github.com/litnimax/odoo-asterisk-dialer/blob/master/models/dialer.py#L218

_______________________________________________
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