bug? difference in module update between trytond-admin vs client

98 views
Skip to first unread message

Ul

unread,
Mar 9, 2017, 7:53:17 AM3/9/17
to try...@googlegroups.com
Hello,

I don't know if i found a bug or made a subtle mistake:

I wrote a small module to have list prices and cost prices stored in the
product not just in the template.
If i install or update the module with trytond-admin it works fine, but
when i update any module with the client, it gets broken and the prices
are greyed out in the product(variant) form again. when i update my
module with trytond-admin again it works again.

i use trytond 4.2 with postgresql

the command that gets it running is:
trytond-admin -c ./trytond.conf -d tryton2 -u product_variant_price

i did a DB-dump in the broken state and after running trytond-admin. The
difference are just different timestamps in the tables ir_cache, ir_lang
and ir_model_data and the changed lines in ir_cache and ir_model_data
are listed in another position.
Can this be the reason for a module working or not?

Best Regards,
Ulrich


here the code of my module:

=== product_variant_price/product.py: ===

# -*- coding: utf-8 -*-
import logging

from trytond.pool import PoolMeta

from trytond.model import fields
from trytond.pyson import Eval

from trytond.modules.product import price_digits


__all__ = ['Product']
logger = logging.getLogger(__name__)

STATES = {
'readonly': ~Eval('active', True),
}
DEPENDS = ['active']

class Product:
__metaclass__ = PoolMeta
__name__ = "product.product"

list_price = fields.Property(fields.Numeric('List Price', states=STATES,
digits=price_digits, depends=DEPENDS))
cost_price = fields.Property(fields.Numeric('Cost Price', states=STATES,
digits=price_digits, depends=DEPENDS))

@classmethod
def __setup__(cls):
if not hasattr(cls, '_no_template_field'):
cls._no_template_field = set()
cls._no_template_field.update(['cost_price', 'list_price'])

super(Product, cls).__setup__()

=== product_variant_price/__init__.py : ===

from trytond.pool import Pool
from .product import *


def register():
Pool.register(
Product,
module='product_variant_price', type_='model')

=== product_variant_price/tryton.cfg : ===

[tryton]
version=4.2.0
depends:
ir
product
xml:
product.xml


=== product_variant_price/product.xml : ===

<?xml version="1.0"?>
<tryton>
<data>

<record model="ir.ui.view" id="product_view_form_simple">
<field name="model">product.product</field>
<field name="type" eval="None"/>
<field name="inherit" ref="product.product_view_form_simple"/>
<field name="priority" eval="10"/>
<field name="name">product_form_simple</field>
</record>

</data>
</tryton>

=== product_variant_price/view/procuct_form_simple.xml : ===

<?xml version="1.0"?>
<data>
<xpath expr="/form/field[@name='active']" position="after">
<label name="list_price"/>
<field name="list_price"/>
<label name="cost_price"/>
<field name="cost_price"/>
</xpath>
</data>

Cédric Krier

unread,
Mar 9, 2017, 8:10:06 AM3/9/17
to try...@googlegroups.com
On 2017-03-09 13:52, Ul wrote:
> I wrote a small module to have list prices and cost prices stored in the
> product not just in the template.
> If i install or update the module with trytond-admin it works fine, but
> when i update any module with the client, it gets broken

Without traceback, it is difficult to help.

> and the prices
> are greyed out in the product(variant) form again. when i update my
> module with trytond-admin again it works again.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Ul

unread,
Mar 9, 2017, 8:31:51 AM3/9/17
to try...@googlegroups.com
Am 09.03.2017 um 14:07 schrieb Cédric Krier:
> On 2017-03-09 13:52, Ul wrote:
>> I wrote a small module to have list prices and cost prices stored in the
>> product not just in the template.
>> If i install or update the module with trytond-admin it works fine, but
>> when i update any module with the client, it gets broken
>
> Without traceback, it is difficult to help.
there is no error thrown an so there is no traceback. The only symptom
is that the prices in the variant-form are greyed out and show the
prices from the template.

Ul

unread,
Mar 9, 2017, 9:26:47 AM3/9/17
to try...@googlegroups.com
Am 09.03.2017 um 13:52 schrieb Ul:
> Hello,
>
> I don't know if i found a bug or made a subtle mistake:
>
> I wrote a small module to have list prices and cost prices stored in the
> product not just in the template.
> If i install or update the module with trytond-admin it works fine, but
> when i update any module with the client, it gets broken and the prices
> are greyed out in the product(variant) form again. when i update my
> module with trytond-admin again it works again.
i just found out, that restarting the server does th job too.
so if i update any module from the client the prises don't work any
more, after restart of the server it works again.
I never before had to restart the server after module update, so there
is still something odd, but it has to be a problem in the server memory.
For updating with trytond-admin i always stopped the server, so it the
memory was new initialized at restart.
>
> i did a DB-dump in the broken state and after running trytond-admin. The
> difference are just different timestamps in the tables ir_cache, ir_lang
> and ir_model_data and the changed lines in ir_cache and ir_model_data
> are listed in another position.
i've even seen the behavior without the dumps changing, so it has
nothing to do with the DB.

Cédric Krier

unread,
Mar 9, 2017, 9:35:06 AM3/9/17
to try...@googlegroups.com
On 2017-03-09 14:30, Ul wrote:
> Am 09.03.2017 um 14:07 schrieb Cédric Krier:
> > On 2017-03-09 13:52, Ul wrote:
> >> I wrote a small module to have list prices and cost prices stored in the
> >> product not just in the template.
> >> If i install or update the module with trytond-admin it works fine, but
> >> when i update any module with the client, it gets broken
> >
> > Without traceback, it is difficult to help.
> there is no error thrown an so there is no traceback. The only symptom
> is that the prices in the variant-form are greyed out and show the
> prices from the template.

Then it would be easier if you could provide a repository to fetch your
module to test.

Cédric Krier

unread,
Mar 9, 2017, 10:05:07 AM3/9/17
to try...@googlegroups.com
On 2017-03-09 15:25, Ul wrote:
> Am 09.03.2017 um 13:52 schrieb Ul:
> > Hello,
> >
> > I don't know if i found a bug or made a subtle mistake:
> >
> > I wrote a small module to have list prices and cost prices stored in the
> > product not just in the template.
> > If i install or update the module with trytond-admin it works fine, but
> > when i update any module with the client, it gets broken and the prices
> > are greyed out in the product(variant) form again. when i update my
> > module with trytond-admin again it works again.
> i just found out, that restarting the server does th job too.
> so if i update any module from the client the prises don't work any
> more, after restart of the server it works again.
> I never before had to restart the server after module update, so there
> is still something odd, but it has to be a problem in the server memory.

It is probably because of the cache in on both side trytond and tryton.
Especially the view definition which is cached on both side.

Indeed I think you got in a special case where your module change the
Model definition without changing the XML view. So the previous view
definition stayed in the cache (nothing triggered its refresh).

I do not know if we should manage this special case by dropping the
cache. But even with such call, other instances will not drop the cache
neither.
At some point, updating/installing from the client is by design a
mistake (it is like changing a wheel of a driving car).

Ul

unread,
Mar 9, 2017, 12:22:39 PM3/9/17
to try...@googlegroups.com
Am 09.03.2017 um 16:02 schrieb Cédric Krier:
> On 2017-03-09 15:25, Ul wrote:
>> Am 09.03.2017 um 13:52 schrieb Ul:
>>> Hello,
>>>
>>> I don't know if i found a bug or made a subtle mistake:
>>>
>>> I wrote a small module to have list prices and cost prices stored in the
>>> product not just in the template.
>>> If i install or update the module with trytond-admin it works fine, but
>>> when i update any module with the client, it gets broken and the prices
>>> are greyed out in the product(variant) form again. when i update my
>>> module with trytond-admin again it works again.
>> i just found out, that restarting the server does th job too.
>> so if i update any module from the client the prises don't work any
>> more, after restart of the server it works again.
>> I never before had to restart the server after module update, so there
>> is still something odd, but it has to be a problem in the server memory.
>
> It is probably because of the cache in on both side trytond and tryton.
> Especially the view definition which is cached on both side.
>
> Indeed I think you got in a special case where your module change the
> Model definition without changing the XML view. So the previous view
> definition stayed in the cache (nothing triggered its refresh).
The strange thing is, that it does not work anymore if i update a
completely independent module. For example:
1. everything is working all right
2. i update stock_lot with the client interface
3. the prices in the product are grayed out and show the prices of the
template
4. i restart the server
5. eyerything works fine again

>
> I do not know if we should manage this special case by dropping the
> cache. But even with such call, other instances will not drop the cache
> neither.
> At some point, updating/installing from the client is by design a
> mistake (it is like changing a wheel of a driving car).
of course, but its just faster/easier in development if it works as usual.

And it could have been possible that you know the issue and just say
something like: "just call this method in cls.setup() and it works" so
it was worth asking...


Cédric Krier

unread,
Mar 9, 2017, 1:25:06 PM3/9/17
to try...@googlegroups.com
Humm, it is more and more interesting.
I think the problem relies in the fact that when updating the pool call
__setup__ after each module but when started normally the __setup__ is
only called once.
So the _no_template_field is not always filled when __setup__ is called.
But normally the Product.__setup__ should not override existing field.

By the way, you do not need to your fields in _no_template_field, this
is only for field that should not be duplicate are not defined on
Product.

Robert Schöftner

unread,
Jul 6, 2017, 10:02:01 AM7/6/17
to try...@googlegroups.com
Hi,

Am Donnerstag, 9. März 2017, 19:22:36 CEST schrieb Cédric Krier:
> > The strange thing is, that it does not work anymore if i update a
> > completely independent module. For example:
> > 1. everything is working all right
> > 2. i update stock_lot with the client interface
> > 3. the prices in the product are grayed out and show the prices of the
> > template
> > 4. i restart the server
> > 5. eyerything works fine again
>
> Humm, it is more and more interesting.
> I think the problem relies in the fact that when updating the pool call
> __setup__ after each module but when started normally the __setup__ is
> only called once.
> So the _no_template_field is not always filled when __setup__ is called.
> But normally the Product.__setup__ should not override existing field.
>
> By the way, you do not need to your fields in _no_template_field, this
> is only for field that should not be duplicate are not defined on
> Product.

Got the same problem. It seems what happens is when updating,
Product.__setup__ is called before the __setup__ in the custom module had a
chance to manipulate _no_template_field. Also, at this moment, the fields of the
custom module are not registered yet, so the check if the field is already
existing fails, and the field is copied. Seems to be a genuine bug.

mfg
Robert

Reply all
Reply to author
Forward
0 new messages