0

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

strike_noir
  • 4,080
  • 11
  • 57
  • 100
  • Could you please add what the search is finding exactly? A better example would really help. Maybe you get some records from Odoo's cache. If yes, there should be something in your code, which could help to, so please add that, too. – CZoellner Dec 10 '18 at 16:17
  • Hmm my code is very long, around 800 lines. If you interested to have a look, I can send it. I cannot split the code into smaller pieces, because of the many conditional requirements that I checked. – strike_noir Dec 10 '18 at 18:31
  • I meant the part just before the search ;-) – CZoellner Dec 10 '18 at 18:56
  • I uploaded the code to pastebin.com please have a look. – strike_noir Dec 11 '18 at 08:51
  • The issue occur in line 801 – strike_noir Dec 11 '18 at 09:19
  • And you're really sure that `data = mcu_data.search([["mcu_record_line_id", "=", rec_id]])` on line 857 will not fetch more than one record? Or that in between that for loop around this line, that there won't be new records created in cache (not in db, because it is one transaction)? – CZoellner Dec 11 '18 at 09:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/185066/discussion-between-strike-noir-and-czoellner). – strike_noir Dec 11 '18 at 12:47
  • can you post the error message please – Charif DZ Dec 11 '18 at 16:17

1 Answers1

0

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.

strike_noir
  • 4,080
  • 11
  • 57
  • 100