Odoo Help


Raise validation error is blocking the flow

on 9/7/15, 9:28 AM 2,251 views

inside create method i have an if condition. in the condition i am performing some insertion. code is not giving any error but record is not inserting into the db, due to the last line raise validation error. if remove that and give return something then the record is inserting into db. how to avoid this ?

def create(self, cr, uid, vals, context=None):

reserve_item_id = vals['reserve_item_id' 

result = self.pool.get('item.item').browse(cr, uid, reserve_item_id)  

item_count = result.item_count

if result.item_count - result.reserve_count == 0:





cr.execute("INSERT INTO email_email (mail_user_id,mail_item_id) VALUES (%s, %s)", (uid, reserve_item_id))

raise ValidationError("No Item available")

Hi Pavan, my issues resolved after using curson.commit(). Thank you

on 9/8/15, 7:11 AM
On 9/8/15, 1:35 AM


After your cr.execute() statement, you can call "cr.commit()", that will save your record in the database, and let your exception call.

One more thing, inspite your record will be created in the database with the values you are inserting, but its better if you pass odoos default field values also, as create function didn't called successfully, these values will not be inserted.[create_uid, create_date, write_date, write_uid.]

Hope it helps

On 9/7/15, 10:27 AM

Hi Yenthe,

Thanks for the reply, i have as like below

from openerp.modules.registry import RegistryManager

newcr = RegistryManager.get(cr.dbname).cursor()

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


still i am facing same issue, can you please help on this

If I'm not mistaking the problem is that you're using self.ppol.get which is still not using your new cursor. Your new record is still created with the default cursor? Do your cr.execute with new new cursor (newcr)

on 9/7/15, 11:01 AM
On 9/7/15, 10:05 AM

Hi Nagarjuna,

The simple answer is you can't with the way you're trying to. When Odoo runs through this function it will start checking things, you then do your cr.execute which works fine but the moment it hits your ValidationError it will do a roll-back. The default behaviour by Odoo is to do a transactional rollback when there is a ValidationError.
You could however avoid this by creating a separate transaction. Transactions are bound to cursors so you need to get a new cursor to the current database, something along the lines of:

newcr = RegistryManager.get(cr.dbname).cursor() 

With the new cursor you can do your transaction and then the ValidationError won't do a rollback since it is a separate cursor. (Don't forget to open and close that cursor).


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 9/7/15, 9:28 AM
Seen: 2251 times
Last updated: 9/8/15, 7:11 AM