Fields.related fields cause recursion on copy(), fields.related calls write() with unrelated model and fields!

Bug #544087 reported by Sebastien LANGE - http://www.Syleam.fr
32
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Fix Released
High
Unassigned
Trunk
Fix Released
High
Unassigned

Bug Description

I create partner with 2 partner adresss and after I tried to duplicate this partner and we have this issue :

  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/orm.py", line 2922, in write
    result += self._columns[field].set(cr, self, id, field, vals[field], user, context=rel_context) or []
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/fields.py", line 710, in set
    self._fnct_inv(obj, cr, user, id, name, value, self._fnct_inv_arg, context)
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/fields.py", line 750, in _fnct_write
    if not t_data[self.arg[i]]:
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/orm.py", line 198, in __getitem__
    datas = self._table.read(self._cr, self._uid, ids, fffields, context=self._context, load="_classic_write")
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/orm.py", line 2513, in read
    result = self._read_flat(cr, user, select, fields, context, load)
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/orm.py", line 2639, in _read_flat
    res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/fields.py", line 438, in get
    ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id, 'in', ids)], limit=self._limit, context=context)
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/orm.py", line 3339, in search
    (qu1, qu2, tables) = self._where_calc(cr, user, args, context=context)
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/orm.py", line 3319, in _where_calc
    e = expression.expression(args)
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/expression.py", line 71, in __init__
    if not reduce(lambda acc, val: acc and (self._is_operator(val) or self._is_leaf(val)), exp, True):
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/expression.py", line 71, in <lambda>
    if not reduce(lambda acc, val: acc and (self._is_operator(val) or self._is_leaf(val)), exp, True):
  File "/home/oerp/openerp/trunk_20100316/server/bin/osv/expression.py", line 43, in _is_leaf
    and (((not internal) and element[1] in OPS) \
RuntimeError: maximum recursion depth exceeded in cmp

Changed in openobject-server:
importance: Undecided → Medium
milestone: none → 5.2
status: New → Confirmed
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello,

Can you please and apply this patch?

Thanks.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Sebastien LANGE,

Would you please check this patch and tell us the apparent behaviour?

Thanks.

summary: - [Partner] RuntimeError: maximum recursion depth exceeded in cmp
+ Fields.related fields cause recursion on copy()
Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote : Re: Fields.related fields cause recursion on copy()

Hi Jay

I have apply your patch in trunk, but i have this traceback

[2010-03-31 11:53:08,034] ERROR:web-services:[01]: Traceback (most recent call last):
[2010-03-31 11:53:08,034] ERROR:web-services:[02]: File "/home/alncchau/tmp/commdays2010/server/bin/osv/osv.py", line 57, in wrapper
[2010-03-31 11:53:08,034] ERROR:web-services:[03]: return f(self, dbname, *args, **kwargs)
[2010-03-31 11:53:08,034] ERROR:web-services:[04]: File "/home/alncchau/tmp/commdays2010/server/bin/osv/osv.py", line 120, in execute
[2010-03-31 11:53:08,035] ERROR:web-services:[05]: res = pool.execute_cr(cr, uid, obj, method, *args, **kw)
[2010-03-31 11:53:08,035] ERROR:web-services:[06]: File "/home/alncchau/tmp/commdays2010/server/bin/osv/osv.py", line 110, in execute_cr
[2010-03-31 11:53:08,035] ERROR:web-services:[07]: return getattr(object, method)(cr, uid, *args, **kw)
[2010-03-31 11:53:08,035] ERROR:web-services:[08]: File "/home/alncchau/tmp/commdays2010/server/bin/addons/base/res/partner/partner.py", line 172, in copy
[2010-03-31 11:53:08,035] ERROR:web-services:[09]: return super(res_partner, self).copy(cr, uid, id, default, context)
[2010-03-31 11:53:08,035] ERROR:web-services:[10]: File "/home/alncchau/tmp/commdays2010/server/bin/osv/orm.py", line 3481, in copy
[2010-03-31 11:53:08,035] ERROR:web-services:[11]: new_id = self.create(cr, uid, data, context)
[2010-03-31 11:53:08,035] ERROR:web-services:[12]: File "/home/alncchau/tmp/commdays2010/server/bin/osv/orm.py", line 3169, in create
[2010-03-31 11:53:08,035] ERROR:web-services:[13]: result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or []
[2010-03-31 11:53:08,035] ERROR:web-services:[14]: File "/home/alncchau/tmp/commdays2010/server/bin/osv/fields.py", line 710, in set
[2010-03-31 11:53:08,035] ERROR:web-services:[15]: self._fnct_inv(obj, cr, user, id, name, value, self._fnct_inv_arg, context)
[2010-03-31 11:53:08,036] ERROR:web-services:[16]: File "/home/alncchau/tmp/commdays2010/server/bin/osv/fields.py", line 764, in _fnct_write
[2010-03-31 11:53:08,036] ERROR:web-services:[17]: obj.pool.get(field_detail['object']).write(cr,uid,[t_id],{args[-1]:values}, context=context)
[2010-03-31 11:53:08,036] ERROR:web-services:[18]: File "/home/alncchau/tmp/commdays2010/server/bin/osv/orm.py", line 2846, in write
[2010-03-31 11:53:08,036] ERROR:web-services:[19]: if not isinstance(self._columns[field], fields.related):
[2010-03-31 11:53:08,036] ERROR:web-services:[20]: UnboundLocalError: local variable 'fields' referenced before assignment

I don't test in 5.0

Regards

summary: - Fields.related fields cause recursion on copy()
+ Fields.related fields cause recursion on copy(), fields.related calls
+ write() with unrelated model and fields!
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Guys,

Here is an improved version of the patch which will solve the problem.
Kindly apply this one and let us know the happenings.

Thanks.

Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi Jay

Now it works, thanks

Regards,

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Thank you for the feedback Christophe,
It has been fixed by revision 2024 <email address hidden>.

Revision history for this message
Stephane Wirtel (OpenERP) (stephane-openerp) wrote :

I provide the following patch for the stable version

Revision history for this message
Stephane Wirtel (OpenERP) (stephane-openerp) wrote :

I provide the following patch for the stable version

Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Jay, i have this problem in trunk, and not in 5.0 (but the problem exist as well)

Regards,

Revision history for this message
Stephane Wirtel (OpenERP) (stephane-openerp) wrote :

Jay,

I just reverted your code, because your patch is for stable, but the issue is for trunk.

Can you provide a patch for stable ?

Thanks

Revision history for this message
Stephane Wirtel (OpenERP) (stephane-openerp) wrote :

Can you check your bug with this bugfix ?

Thanks

Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Yes it works, thanks

This patch must be test in 5.0 before commit

Regards,

Revision history for this message
Richard (John) Nopkins@Servosoft (richard-nopkins) wrote :

hi *!,

the patch was gud and i have checked it for diff conditions, it is superb!
why its nt fixed in stable?so irresponsible it is.

i am not techie expert, but I saw the code and its smooth like a butter.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Stephane and Christophe Chauvet,

The problem appears instable when you copy any partner with country/city.

Kindly check again.

Thanks.

Revision history for this message
Stephane Wirtel (OpenERP) (stephane-openerp) wrote :

@John, I reverted this patch because the bug was declared only for trunk.

Even if the patch is right, I prefer to avoid a regression.

I discussed with Jay and now, we can apply his patch on the stable.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.