Issue 6672

Title
AttributeError: "product.configuration.default_cost_price_method,1" has no attribute "company"
Priority
bug
Status
resolved
Nosy list
angel, ced, meigallodixital, pokoli, reviewbot, roundup-bot
Assigned to
ced
Keywords
review

Created on 2017-07-25.10:56:09 by pokoli, last changed 30 months ago by roundup-bot.

Files

File name Uploaded Type Details
scenario_issue6672.rst pokoli, 2018-04-06.10:05:57 text/x-rst view
scenario_issue6672.rst ced, 2018-04-06.11:21:49 text/plain view

Messages

New changeset fe3b68b8c25e by Cédric Krier in branch '4.6':
Filter extra pattern in get_multivalue and set_multivalue
http://hg.tryton.org/trytond/rev/fe3b68b8c25e

New changeset 2743c6522631 by Cédric Krier in branch '4.4':
Filter extra pattern in get_multivalue and set_multivalue
http://hg.tryton.org/trytond/rev/2743c6522631
New changeset 0d8679b196be by Cédric Krier in branch 'default':
Filter extra pattern in get_multivalue and set_multivalue
http://hg.tryton.org/trytond/rev/0d8679b196be

New changeset 73684280352a by Cédric Krier in branch 'default':
Add tests for extra pattern in get_multivalue and set_multivalue
http://hg.tryton.org/trytond/rev/73684280352a
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2018-04-06.11:21:49
I found the problem. It is that MultiValueMixin.get_multivalue, when it does not find a value, call default method with the same pattern. And the Template.default_cost_price_method call get_multivalue of Configuration with also the same pattern. But Configuration for the cost_price_method does not use a CompanyValueMixin so the extra company pattern breaks the pattern matching.
I think the design to pass the pattern is right because we want it to be flexible and extensible. In case for example, that a module change the cost_price_method configuration model into a CompanyValueMixin.
So I think we should be lazy in MultiValueMixin against extra pattern clause.

Here is review47291003

By the way, I re-upload the script fixed.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2018-04-06.10:06:29
Here is file2582 which can be run to reproduce the issue.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2018-04-05.14:01:44
I mean a scenario that I can run.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2018-04-05.13:55:01
See msg37554

It's important that you create first the product (with only one company in the database) and then create a new company. Once you access the product form with the new created company in the context the error is raised.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2018-04-05.13:34:23
Could you provide a reproducible testing scenario?
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2018-04-05.10:30:54
Issue is still present with issue7205
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2018-03-24.18:43:02
I'm wondering if issue7205 would not have fixed this issue.
Author: [hidden] (angel)
Date: 2018-02-14.16:59:23
I have same issue after upgrade database to 4.7
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2018-01-11.11:03:35
Indeed I can reproduce the issue on the demo database. The traceback is raised when accessing the product with a company that does not have any value defined. 

In the demo database this can be reproduced by creating an user that access the Dunder Mifflin Inc company. Then go to the product list and open the form view of any product and you will see the traceback described in msg34760
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2017-10-31.14:39:12
Indeed I'm still reproducing it on version 4.7, which proves that's not a cache issue.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2017-10-11.18:08:55
Maybe the cached directory of pip.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2017-10-11.18:06:26
I cleared it several times, upgraded tox and the issue still repeat.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2017-10-11.18:00:07
Clean your tox environment.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2017-10-11.17:47:39
Indeed its something strange as I can only reproduce when running a test scenario of a module under tox. The bug does not raise when running the run-tests script. 

I can not reproduce it on a normal database with the same configuration as the test scenario. 

Any idea?
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2017-09-30.00:06:14
I can not reproduce the traceback.
Please provide a scenario.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2017-08-17.17:16:56
Indeed, I can reproduce the traceback when trying to update the product cost price using the wizard. 

I added review35571002 which should fix it.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2017-07-25.11:45:09
On 2017-07-25 11:27, Sergi Almacellas Abellana wrote:
> El 25/07/17 a les 11:19, Cédric Krier ha escrit:
> > For me, it is wrong to add CompanyMultiValueMixin because the original design did not want to have multi-company for that value.
> 
> Then how we should fix the Attribute error?

I do not know.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2017-07-25.11:45:07
On 2017-07-25 11:17, Sergi Almacellas Abellana wrote:
> El 25/07/17 a les 11:16, Cédric Krier ha escrit:
> > I do not understand the first sentence of msg34760.
> 
> Let me clarify: It should be possible to define a diferent default_cost_price_method on each company created on the system.

I do not agree, this is customization.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2017-07-25.11:27:38
El 25/07/17 a les 11:19, Cédric Krier ha escrit:
> For me, it is wrong to add CompanyMultiValueMixin because the original design did not want to have multi-company for that value.

Then how we should fix the Attribute error?
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2017-07-25.11:19:35
For me, it is wrong to add CompanyMultiValueMixin because the original design did not want to have multi-company for that value.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2017-07-25.11:17:56
El 25/07/17 a les 11:16, Cédric Krier ha escrit:
> I do not understand the first sentence of msg34760.

Let me clarify: It should be possible to define a diferent default_cost_price_method on each company created on the system.
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2017-07-25.11:16:29
I do not understand the first sentence of msg34760.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2017-07-25.10:56:09
The default_cost_price of the product.configuration should be possible to have a different value depending on the company. 

Since changeset d0488db05044 this causes the following crash:

Exception raised:
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest scenario_base_workflows.rst[77]>", line 1, in <module>
        template.save()
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/proteus/__init__.py", line 101, in newfunc
        return self.func(owner, [instance], *args, **kwargs)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/proteus/__init__.py", line 758, in save
        ids = proxy.create(values, context)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/proteus/config.py", line 172, in __call__
        result = rpc.result(meth(*args, **kwargs))
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/modules/product/product.py", line 159, in create
        return super(Template, cls).create(vlist)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/modelsql.py", line 595, in create
        field.set(cls, fname, *fargs)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/one2many.py", line 217, in set
        Target.create(to_create)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/modules/product_variant_unique/product.py", line 312, in create
        return super(Product, cls).create(vlist)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/modelsql.py", line 604, in create
        cls._validate(sub_records)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/modelstorage.py", line 1088, in _validate
        value = getattr(record, field_name)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/modelstorage.py", line 1369, in __getattr__
        read_data = self.read(list(ids), ffields.keys())
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/modelsql.py", line 778, in read
        getter_results = field.get(ids, cls, field_list, values=result)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/function.py", line 102, in get
        return dict((name, call(name)) for name in names)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/function.py", line 102, in <genexpr>
        return dict((name, call(name)) for name in names)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/function.py", line 96, in call
        return dict((r.id, method(r, name)) for r in records)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/function.py", line 96, in <genexpr>
        return dict((r.id, method(r, name)) for r in records)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/modules/product/product.py", line 264, in get_template
        value = getattr(self.template, name)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/modelstorage.py", line 1369, in __getattr__
        read_data = self.read(list(ids), ffields.keys())
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/modelsql.py", line 778, in read
        getter_results = field.get(ids, cls, field_list, values=result)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/function.py", line 102, in get
        return dict((name, call(name)) for name in names)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/function.py", line 102, in <genexpr>
        return dict((name, call(name)) for name in names)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/function.py", line 96, in call
        return dict((r.id, method(r, name)) for r in records)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/fields/function.py", line 96, in <genexpr>
        return dict((r.id, method(r, name)) for r in records)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/multivalue.py", line 53, in _multivalue_getter
        value = self.get_multivalue(name)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/modules/company/model.py", line 25, in get_multivalue
        name, **pattern)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/multivalue.py", line 46, in get_multivalue
        setattr(value, name, func(**pattern))
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/modules/product/product.py", line 137, in default_cost_price_method
        'default_cost_price_method', **pattern)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/multivalue.py", line 41, in get_multivalue
        values = self.__values(name, pattern, match_none=False)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/multivalue.py", line 38, in __values
        if v.match(pattern, match_none=match_none)]
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/multivalue.py", line 87, in match
        return super(ValueMixin, self).match(pattern, match_none=match_none)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/match.py", line 12, in match
        value = getattr(self, field)
      File "/builds/base/.tox/py27-sqlite/lib/python2.7/site-packages/trytond/model/modelstorage.py", line 1226, in __getattr__
        raise AttributeError('"%s" has no attribute "%s"' % (self, name))
    AttributeError: "product.configuration.default_cost_price_method,1" has no attribute "company"
History
Date User Action Args
2018-04-20 19:16:42roundup-botsetmessages: + msg40300
2018-04-09 10:52:31roundup-botsetstatus: testing -> resolved
nosy: + roundup-bot
messages: + msg39905
2018-04-06 11:30:08reviewbotsetmessages: + msg39838
2018-04-06 11:21:50cedsetstatus: chatting -> testing
reviews: 35571002 -> 35571002,47291003
messages: + msg39837
files: + scenario_issue6672.rst
assignedto: ced
2018-04-06 10:06:29pokolisetmessages: + msg39832
2018-04-06 10:05:57pokolisetfiles: + scenario_issue6672.rst
2018-04-05 14:01:45cedsetmessages: + msg39807
2018-04-05 13:55:02pokolisetmessages: + msg39806
2018-04-05 13:34:23cedsetmessages: + msg39805
2018-04-05 10:30:54pokolisetstatus: testing -> chatting
messages: + msg39758

Showing 10 items. Show all history (warning: this could be VERY long)