_inherits from product break search

Bug #362280 reported by Marcel van der Boom (HS-Development BV)
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo GTK Client (MOVED TO GITHUB)
Invalid
Undecided
Unassigned
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
Anup(SerpentCS)
Odoo Web Client
Invalid
Undecided
Unassigned

Bug Description

I have a couple of objects which are using the _inherits = {'product.product' : 'product_id'} type construct.

On these object i have a simple list view which displays code, name and state. When using the search fields i get this error:

ProgrammingError: column product_product.name does not exist

originating from this query:

select mything_mything.id from "mything_mything","product_product"
where (product_product.id=mything_mything.product_id) AND ((1=1) AND (product_product.name ilike 'IMP')) order by id limit 80

The last bit in the where clause causes an error, because product does not have a column name.

Related branches

Revision history for this message
Marcel van der Boom (HS-Development BV) (mrb) wrote :

Darn, this is for the gtk client. What is the proper procedure to move it there?

Navrang Oza (noz-tiny)
Changed in openobject-client-web:
status: New → Invalid
Revision history for this message
Marcel van der Boom (HS-Development BV) (mrb) wrote :

Just tested this with the hotel module, which uses the same construct, *does* seem to affect *both* web and gtk

Changed in openobject-client-web:
status: Invalid → New
Revision history for this message
Marcel van der Boom (HS-Development BV) (mrb) wrote :

I'm trying to create a workaround for this by overriding the search method of my objects. I have so far, something like this:

  def search(self, cr, uid, args, offset=0, limit=2000, order=None, context=None, count=False):
      # Do the search on products and get their ids
      pids = self.pool.get('product.product').search(cr, uid, args, offset, limit, order,context=context,count=count)

      return super(substance,self).search(cr,uid,[['product_id','in',pids],offset,limit,order,context=context,count=count)

Does this makes sense to pursue further?
(thinking about the bug, i think its actually a server bug)

Changed in openobject-client-web:
status: New → Invalid
Changed in openobject-client:
status: New → Invalid
summary: - inherits from product break search
+ _inherits from product break search
Revision history for this message
Marcel van der Boom (HS-Development BV) (mrb) wrote :

The code in https://bugs.launchpad.net/openobject-server/+bug/362280/comments/3 more or less works, as long as the returned number of records is less than the current limit (the '80' by default).

If it is larger, then the search returns the count, instead of the ids found.

Revision history for this message
Marcel van der Boom (HS-Development BV) (mrb) wrote :

Workaround:
  # Second level _inherits, break search. See bug #362280
  # This workaround only works in the fields are also in product.product
  def search(self, cr, uid, args, offset=0, limit=None, order=None, context={}, count=False):
      # If there is nothing in args, dont bother
      if len(args):
          # Do the search on products and get their ids, make sure count is
          # false, otherwise resultsets larger than limit will produce an error
          product_ids = self.pool.get('product.product').search(cr, uid, args, offset, limit, order,context,False)

          # Use the product ids to search the corresponding
          args = [('product_id','in',product_ids)]

      return super(YOURCLASSNAME,self).search(cr,uid,args,offset,limit,order,context,count)

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

Hello Marcel,

The query you made on product_product.name is not a valid one.

The DB structure will not have all the fields on product.product,few belong to its parent viz. product.template.

Can you describe exactly what you want to perform with this?

Thank you.

Changed in openobject-server:
status: New → Incomplete
Revision history for this message
Marcel van der Boom (HS-Development BV) (mrb) wrote :

Jay,

The query is not constructed manuallyby us, but taken as an example from the server logs.

The issue is that the server does not correctly construct the query. When an object is constructed as child from product.product (which in turn is a child of product.template) the server assumes that fields used for searching will come from the immediate parent, which is not always the case.

If i remember correctly the 'hotel' module suffers from this bug too, so perhaps it is easiest to test with that module.

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

Hi Marcel,

May be its a misunderstanding,

you try to link 3 objects, is it so?

Ok, let me check with 'Hotel' Module and let you know.

Thank You.

Revision history for this message
Marcel van der Boom (HS-Development BV) (mrb) wrote :

I'm not sure what you mean by 'link 3 objects'. I simply inherit from the object 'product', which of course in turn inherits from product_template. So, yes there are 3 objects involved:

product.template ⇢ product.product ⇢ mything.mything

Changed in openobject-server:
importance: Undecided → Medium
status: Incomplete → Confirmed
Changed in openobject-server:
status: Confirmed → In Progress
assignee: nobody → Jay (Open ERP) (jvo-openerp)
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Marcel van der Boom ,

Would you please apply this patch and let us know for the new behaviour?

Thank you for reporting,this valuable report has improved our product.

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

Fixed by revision 1841 <email address hidden>.

Thank you.

Changed in openobject-server:
status: In Progress → Fix Released
Revision history for this message
Husen Daudi (husendaudi) wrote :

reverted patch. need to review again.

Changed in openobject-server:
status: Fix Released → New
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Review in progress.

Changed in openobject-server:
status: New → In Progress
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Thank you for the patience.

Recommitted after refactoring with revision 1819 <email address hidden>.

Changed in openobject-server:
status: In Progress → Fix Released
Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

This patch does not solve the problem for me, I do have to change the code the way I describe in:
http://www.openobject.com/forum/post56287.html#56287

Revision history for this message
Adrien Guichard (guichard-adrien) wrote :
Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

It does not solve the problem with your patch in generic manner.
Need to look further more.
It has been fixed in trunk.
Would you please check it?
Thanks.

Changed in openobject-server:
status: Fix Released → Confirmed
Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

I installed trunk, but I cannot create a db or migrate an old db.

  File "/home/adrien/toto/openerp/trunk/server/bin/osv/orm.py", line 491, in _field_create
    if cols[k][key] != vals[key]:
KeyError: 'selectable'

Will try again tomorrow.

Thanks

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Adrien,

   I have checked in the stable version and found the solution which is attached here. Would you please test the attached patch and notify us?

Thanks.

Changed in openobject-server:
status: Confirmed → In Progress
Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

Hello Anup,

Unfortunately, it does not work on openerp-5.0.10. I get the following stack trace:

Environment Information :
System : Linux-2.6.33.4-server-2mnb-i686-with-mandrake-2010.1-Official
OS Name : posix
LSB Version: lsb-4.0-ia32:lsb-4.0-noarch:*
Distributor ID: MandrivaLinux
Description: Mandriva Linux 2010.1
Release: 2010.1
Codename: Henry_Farman
Operating System Release : 2.6.33.4-server-2mnb
Operating System Version : #1 SMP Fri May 21 10:56:19 UTC 2010
Operating System Architecture : 32bit
Operating System Locale : fr_FR.UTF-8
Python Version : 2.6.5
OpenERP-Client Version : 5.0.10
Last revision No. & ID :Bazaar Package not Found !Traceback (most recent call last):
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/netsvc.py", line 245, in dispatch
    result = LocalService(service_name)(method, *params)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/netsvc.py", line 74, in __call__
    return getattr(self, method)(*params)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/addons/base_module_record/base_module_record.py", line 38, in execute
    res = super(recording_objects_proxy, self).execute(*args, **argv)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/service/web_services.py", line 576, in execute
    res = service.execute(db, uid, object, method, *args)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/osv/osv.py", line 58, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/osv/osv.py", line 119, in execute
    res = pool.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/osv/osv.py", line 111, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/osv/orm.py", line 3023, in search
    (qu1, qu2, tables) = self._where_calc(cr, user, args, context=context)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/osv/orm.py", line 3005, in _where_calc
    qu1, qu2 = e.to_sql()
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/osv/expression.py", line 432, in to_sql
    q, p = self.__leaf_to_sql(e, table)
  File "/home/adrien/toto/openerp/openerp-server-5.0.10/bin/osv/expression.py", line 365, in __leaf_to_sql
    instr = ','.join([table._columns[left]._symbol_set[0]] * len_after)
KeyError: 'categ_id'

If you want me to send you my db and my module, just ask me. I will try to debug the code on my side.

Thanks for your support,
Adrien

Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

Anup, look after to_sql method, tables need to be sorted against the expressions order, then, for the jointure, we need other tables.

If I search against "categ_id", the only expression when KeyError is:
('categ_id', 'in', [...some integers...])

Table 'product_template' should be at index 0 (the value id "i", not "index").

so we cannot write:
123(or 2) self.__tables[index] = working_table
but we have to let
123(or 2) self.__tables[i] = working_table

Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

I change expression.py, in order to suppress "index" variable and to keep tables order OK. The code is the following (sorry, I could have attached a patch) :

From line 117 to 130 in expression.py (Openerp 5.0.10), after having applied the last patch:
            if left in table._inherit_fields:
                while True:
                    field = main_table._columns.get(fargs[0], False)
                    if field:
                        working_table = main_table
                        if self.__tables.has_key(i):
                            self.__tables[len(self.__tables)] = self.__tables[i]
                        self.__tables[i] = working_table
                        break
                    working_table = main_table.pool.get(main_table._inherit_fields[left][0])
                    if working_table not in self.__tables.values():
                        self.__joins.append(('%s.%s=%s.%s' % (working_table._table, 'id', main_table._table, main_table._inherits[working_table._name]), working_table._table))
                        self.__tables[len(self.__tables)] = working_table
                    main_table = working_table

Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

remove index variable, ensure correct tables order.

I do not know how to create a proper patch, sorry. This patch is to be applied over your patch.

Thanks for your support,
Adrien

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Andrien,

  I have tested at my side with different criteria but it works as it should. Would you please attach the code how exactly you are using the search with _inherits, so that I can check what exactly the problem is.

Thanks.

Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

Test case allowing to reproduce the problem:
1. install the module
-> unzip the file in addons directory,
-> update module list,
-> search for "test" in name field (in module list).

2. Create a product, that inherits from product.product:
-> go to Testcase/My Base Product/Child,
-> press on CTRL + L to switch form view,
-> enter values, and save

3. Search against categ_id
-> press CTRL + L to switch to tree view
-> Type something in "Category" field

=> Crash here !!!

Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

Anup, tell me if you can reproduce the bug. The patch I propose solve the problem.

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

Hello Adrien,

We confirm the issue.

Would you please check with the attached patch?

Thank you for being co-operative.

Changed in openobject-server:
assignee: Jay (Open ERP) (jvo-openerp) → Anup (Open ERP) (ach-openerp)
milestone: none → 5.0.11
Revision history for this message
Adrien Guichard (guichard-adrien) wrote :

Thanks Jay, the patch is OK for me!

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

Thanks for the response.
It has been fixed by revision 2062 <email address hidden>.

Changed in openobject-server:
status: In Progress → Fix Released
Revision history for this message
Marcel van der Boom (HS-Development BV) (mrb) wrote :

Just a confirmation as original bug reporter, the patch is OK for me too.

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

Thanks Marcel.

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

Other bug subscribers

Remote bug watches

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