Search code examples
pythonodooodoo-8

Odoo ghost record


When I do model search in Odoo, I randomly encounter extra record which does not exist in the database. For example:

Supposedly this search statement only returns one record

mytable = self.env["my.table"]
mydata = mytable.search([('something_uid', '=', 1)]) #this should only return one

But when I check for mydata.id I get singleton error because the result is not one. There is an extra record, that when I double check it is not present in the table.

Is it because there is an bug in my code? I discover this in multiple occasions. But I can't point out where there problem is.

Update

I uploaded the code to pastebin.com please have a look https://pastebin.com/gk0rDfuy

PS. I'm using Odoo 8 but I'm curious if later versions of Odoo has similar experience


Solution

  • It seems Odoo's ORM uses a kind of transaction for its database operations. This explains why when I query the database while I put a breakpoint in the code, I could not find the records the code is pointing to.

    And the database commit the records only if the code completes. This also explains why even if I quit from the breakpoint it does not commit the records. As quiting from the breakpoint does not trigger Odoo's commit operation.

    By checking the other portion of the codes solves the issue.