This question has been flagged

Hi.

I have a cycle like this.

for i in ids:

 self.pool.get('product.product').create(cr, uid, vals, context = context)

 cr.commit()

Now in empty system this is not cause any matter, but what is a risk, for this kind of execution? Think of live system with user activites, and so on.

If has what is a different's between 6.1, 7.0, 8.0 versions?

Regards.

Laci.

 

 

Avatar
Discard

Odoo auto commits the changes you make at the end of the transaction, why are you explicitly calling cr.commit() yourself?

Author

Hi. Thanks for the reply. So I need the data sometimes as well, because I make a large calculation what is take's a lot of time. Sometimes this calculation cannot reach the end of transaction, because some exception raised, but some semi finish data is important for me, and this case I lost all of the calculated data. (I working on some diff. resource planner, what is need to recalculate the production, according the daily capacity and shift happening. ) Now I working on an automatic factory builder, what is create all of the things according few input data. (repacking routings, bill of material, create the sem finish parts, work instruction, according few templates) So in this case sometimes I create 200.000 lines In mrp.routing and I lost all, if some raw data is wrong. (template not exist, wrong mrp code and so on ) That's why I need to write manually the results what is ok.

I understand, in that case I don't think there is a risk associated with this, you are simply committing your changes immediately and it's just one line of code, so it shouldn't be a problem.

As long as you're sure that the batches of code you're committing wont cause a problem in case there is a failure, then it shouldn't be a problem. Just make sure to manage your transactions as the other member suggested in the answer to your question.

Best Answer

You should NEVER call cr.commit() yourself, UNLESS you have created your own database cursor explicitly! And the situations where you need to do that are exceptional!

And by the way if you did create your own cursor, then you need to handle error cases and proper rollback, as well as properly close the cursor when you're done with it.

From: https://doc.odoo.com/contribute/15_guidelines/coding_guidelines_framework/#never-commit-the-transaction

Avatar
Discard
Author

Ok. What is the situation whit wizards? This can be commit own self?

can you be more explicit?

Author

Hi Med. Can you explain me how to create an own database cursor, to take safe my activities?

It's in the above response;"And by the way if you did create your own cursor, then you need to handle error cases and proper rollback, as well as properly close the cursor when you're done with it." Keep in mind the "Transaction Isolation". To read: http://www.postgresql.org/docs/9.2/static/transaction-iso.html http://fossies.org/dox/odoo-7.saas-5/classopenerp_1_1sql__db_1_1Cursor.html

A good example: https://github.com/yeahliu/workflow_info/blob/master/controller.py

Author

Thx Med. i will try it soon as possible.