Odoo Help


[SOLVED] KeyError on product variants, could be a bug?

Peter Alabaster
on 1/31/15, 1:26 PM 3,491 views

During development for a project, we realised we would need to set up product variants, so I did some testing.

I set up 3 variants of a demo product and everything worked fine and dandy, I could click through them, and also click on the original product to add/edit more variants.

I then processed a sales order for a variant, and it was all good - until I tried to click on the original product in Sales -> Products, I received a traceback ending with keyerror. Thinking it was a conflict with some of our modules, I tried the same steps on a stock install of Odoo.

Turns out there wasn't a conflict, and the error still shows.

2015-01-31 18:18:23,757 8883 INFO Peter werkzeug: - - [31/Jan/2015 18:18:23] "POST /web/dataset/call_kw/product.template/fields_view_get HTTP/1.1" 200 -
2015-01-31 18:18:24,426 8883 ERROR Peter openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/home/peter/odoo/openerp/http.py", line 530, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/peter/odoo/openerp/http.py", line 567, in dispatch
    result = self._call_function(**self.params)
  File "/home/peter/odoo/openerp/http.py", line 303, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/peter/odoo/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/peter/odoo/openerp/http.py", line 300, in checked_call
    return self.endpoint(*a, **kw)
  File "/home/peter/odoo/openerp/http.py", line 796, in __call__
    return self.method(*args, **kw)
  File "/home/peter/odoo/openerp/http.py", line 396, in response_wrap
    response = f(*args, **kw)
  File "/home/peter/odoo/addons/web/controllers/main.py", line 949, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/peter/odoo/addons/web/controllers/main.py", line 932, in _call_kw
    records = getattr(request.session.model(model), method)(*args, **kwargs)
  File "/home/peter/odoo/openerp/http.py", line 900, in proxy
    result = meth(cr, request.uid, *args, **kw)
  File "/home/peter/odoo/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/peter/odoo/openerp/models.py", line 3109, in read
    result = BaseModel.read(records, fields, load=load)
  File "/home/peter/odoo/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/peter/odoo/openerp/models.py", line 3141, in read
  File "/home/peter/odoo/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/peter/odoo/openerp/models.py", line 3305, in _read_from_database
    res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
  File "/home/peter/odoo/openerp/osv/fields.py", line 1361, in get
    result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
  File "/home/peter/odoo/addons/sale/sale.py", line 1283, in _sales_count
    res[template.id] = sum([p.sales_count for p in template.product_variant_ids])
  File "/home/peter/odoo/openerp/fields.py", line 760, in __get__
  File "/home/peter/odoo/openerp/fields.py", line 853, in determine_value
  File "/home/peter/odoo/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/peter/odoo/openerp/models.py", line 3196, in _prefetch_field
    result = records.read(list(fnames), load='_classic_write')
  File "/home/peter/odoo/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/peter/odoo/openerp/models.py", line 3141, in read
  File "/home/peter/odoo/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/peter/odoo/openerp/models.py", line 3308, in _read_from_database
    vals[f] = res2[vals['id']]
KeyError: 3

NOTE: This error doesn't show if I haven't processed an order containing a variant of the product.

So, is this a bug i should report to Odoo or have I just set things up incorrectly?



Surprisingly enough - yes. I just manually changed the code back to original state and the error no longer shows

OpusVL, Peter Alabaster
on 2/1/15, 11:48 AM


| 6 5 7
Lodz, Poland

On 2/1/15, 12:56 PM

Issue related to this commit

Thankyou, I contacted Odoo and the fix has been pushed upstream

OpusVL, Peter Alabaster
on 2/3/15, 5:23 AM

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

1 follower(s)


Asked: 1/31/15, 1:26 PM
Seen: 3491 times
Last updated: 6/9/17, 6:26 AM