KeyError: 'id' shows when more than 2 entries are inserted

Asked by Shuaib Rahman


i'm trying to develop a new module in openerp 7.0. i have created a py file which creates the table "app_obj". when i save the first data into the table, it works fine. upon inserting the 2nd data and saving, it shows the following error:

OpenERP Server Error
Client Traceback (most recent call last):
  File "D:\OpenERP 7.0-20130828-231133\Server\server\openerp\addons\web\", line 204, in dispatch
  File "D:\OpenERP 7.0-20130828-231133\Server\server\openerp\addons\web\controllers\", line 1054, in search_read
  File "D:\OpenERP 7.0-20130828-231133\Server\server\openerp\addons\web\controllers\", line 1089, in do_search_read
  File "D:\OpenERP 7.0-20130828-231133\Server\server\openerp\addons\web\", line 42, in proxy
  File "D:\OpenERP 7.0-20130828-231133\Server\server\openerp\addons\web\", line 30, in proxy_method
  File "D:\OpenERP 7.0-20130828-231133\Server\server\openerp\addons\web\", line 103, in send

Server Traceback (most recent call last):
  File "D:\OpenERP 7.0-20130828-231133\Server\server\openerp\addons\web\", line 89, in send
  File "D:\OpenERP 7.0-20130828-231133\Server\server\.\openerp\", line 292, in dispatch_rpc
  File "D:\OpenERP 7.0-20130828-231133\Server\server\.\openerp\service\", line 626, in dispatch
  File "D:\OpenERP 7.0-20130828-231133\Server\server\.\openerp\osv\", line 188, in execute_kw
  File "D:\OpenERP 7.0-20130828-231133\Server\server\.\openerp\osv\", line 131, in wrapper
  File "D:\OpenERP 7.0-20130828-231133\Server\server\.\openerp\osv\", line 197, in execute
  File "D:\OpenERP 7.0-20130828-231133\Server\server\.\openerp\osv\", line 185, in execute_cr
  File "D:\OpenERP 7.0-20130828-231133\Server\server\.\openerp\osv\", line 3606, in read
  File "D:\OpenERP 7.0-20130828-231133\Server\server\.\openerp\osv\", line 3729, in _read_flat
KeyError: 2

from the postgresql, i can see that the second entry has an id 2. creating a new database and reinstalling the module does not fix it (which may mean that the error is due to any missing record). and below is the py file:

from osv import osv, fields
# import pooler
import datetime

class app_obj(osv.osv):


    def serial(self, cr, uid, ids, arg1, arg2, context=None):
        return {ids[0]:count}

    def doc_name_change1(self, cr, uid, ids, doc_name2, context=None): #this is an onChange method

        if doc_name2:
            cr.execute("""SELECT id, date_start, date_end FROM doc_info""")

            for r in query_result:
                if doc_name2 == r['id']:
            return {'value': {'from':time_start, 'to':time_end}}

    _name= "app_obj"

    _columns = {
               'app_id': fields.char("Appointment Ref ID", required=True),
               'date':"Date of appointment", required=True),
               'serial': fields.function(serial, method=True, type='integer', string='Serial', readonly=True),
               'doc_name': fields.many2one('doc_info', "Doctor"),
               'p_name': fields.many2one('patient_info',"Patient"),
               'app_start_time': fields.char("Start Time", required=True),
               'app_end_time': fields.char("End Time", required=True),
               'comment': fields.char("Comment"),
               'purpose': fields.many2one('purpose', 'Purpose'),
                'from': fields.datetime("Available from", readonly=True),
                'to': fields.datetime("to", readonly=True),
                'status': fields.many2one('status', "Status"),
                'rel1': fields.many2one('doc_app', "who cares"),

               'app_start_time': '00:00',
               'app_end_time': '00:00',


spent a lot of time trying to find solution online, but no luck.

am developing is windows 7 platform, chrome version 29.0.1547.76 m, in case its relevant.

any help will be greatly appreciated!

Question information

English Edit question
Odoo Server (MOVED TO GITHUB) Edit question
No assignee Edit question
Solved by:
Serpent Consulting Services
Last query:
Last reply:
Revision history for this message
Amit Parik (amit-parik) said :

Its not bug rather then coding mistake, better get an answer from the question!

Revision history for this message
Best Serpent Consulting Services (serpent-consulting-services) said :

Salam Shuaib,

The problem is in your serial().

It should be:

def serial(self, cr, uid, ids, arg1, arg2, context=None):
        res = {}
        count = self.count
        for rec in ids:
             res[rec] = count
        return res

I am not sure what you want to set in serial field, but the above code will fix your issue!

Revision history for this message
Shuaib Rahman (shuaib-q3) said :

thanks a lot ppl.. silly me. couldnt see tht even after hours of wasting time on it.. and then i moved on with everything else, thinking of getting back to it sometime later.
thanks a lot :)