Odoo Help

Welcome!

This community 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.

0

KeyError on product variants, could be a bug?

By
Peter Alabaster
on 1/31/15, 1:26 PM 2,111 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: 127.0.0.1 - - [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
    self._read_from_database(stored)
  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__
    self.determine_value(record)
  File "/home/peter/odoo/openerp/fields.py", line 853, in determine_value
    record._prefetch_field(self)
  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
    self._read_from_database(stored)
  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?

Thanks
Peter

 

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
1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/31/15, 1:26 PM
Seen: 2111 times
Last updated: 3/16/15, 8:10 AM