--unaccent option does not work

Bug #1049653 reported by Damián Soriano
40
This bug affects 8 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Low
OpenERP's Framework R&D
OpenERP Community Backports (Server)
Status tracked in 7.0
6.1
Fix Released
Medium
Yann Papouin
7.0
Invalid
Medium
Yann Papouin

Bug Description

I have OpenERP v6.1 in Ubuntu 12.04 with PostgreSQL. I updated the nightly builds, version: OpenERP Server 6.1-20120910-233309.

I create a new OpenERP database called X.

I installed postgresql-contrib for using unaccent in PostgreSQL and connect to the database X with psql. I execute "create extension unaccent;" to have access to unaccent in the database X.

I start the OpenERP server with the '--unaccent' option.

After all this, if I search over product name, I do not receive the expected result. For example, if I have products 'aeío' and 'aeio' and I search with string 'aeí' I receive only the first product and not the second.

I check the log (using option --log-sql in the server) and I don't see any usage of unaccent function in the querys.

Related branches

Revision history for this message
Damián Soriano (damiansoriano) wrote :

Sorry, I forgot to said that the versión of PostgreSQL is 9.1.

Revision history for this message
Damián Soriano (damiansoriano) wrote :

Amit Parik, why you maked this error as duplicated?

They are both related to unaccent, but they are not the same AFAIAC...

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Damian,

Sorry for inconvenience.

Thanks!

Revision history for this message
Damián Soriano (damiansoriano) wrote :

I think that the problem is when searching in Products, because it uses a subquery here. The subqueries are not parsed correctly to use unaccent(). I made a few changes in the 'expression.py' files and now it is working. I include the new 'expression.py' file that makes things work correctly.

In the file 'openerp/osv/expression.py' In line 639, the lines:

else:
    subselect += ' AND value ' + sql_operator + instr + \
         ') UNION (' \
         ' SELECT id' \
         ' FROM "' + working_table._table + '"' \
         ' WHERE "' + left + '" ' + sql_operator + instr + ")"

should be replaced by the lines:

else:
    if sql_operator in ['like','ilike'] and self.has_unaccent:
        subselect += ' AND value ' + sql_operator + instr + \
             ') UNION (' \
             ' SELECT id' \
             ' FROM "' + working_table._table + '"' \
             ' WHERE unaccent("' + left + '") ' + sql_operator + ' unaccent(' + instr + "))"
    else:
        subselect += ' AND value ' + sql_operator + instr + \
             ') UNION (' \
             ' SELECT id' \
             ' FROM "' + working_table._table + '"' \
             ' WHERE "' + left + '" ' + sql_operator + instr + ")"

With this modifications, if searching in products, the unaccent() function is used.

Also I think (but not quite sure about it) that in line 625 the lines:

subselect = '( SELECT res_id' \
         ' FROM ir_translation' \
         ' WHERE name = %s' \
         ' AND lang = %s' \
         ' AND type = %s'

should be changed with something like this:

if self.has_unaccent:
    subselect = '( SELECT res_id' \
             ' FROM ir_translation' \
             ' WHERE unaccent(name) = unaccent(%s)' \
             ' AND lang = %s' \
             ' AND type = %s'
else:
    subselect = '( SELECT res_id' \
             ' FROM ir_translation' \
             ' WHERE name = %s' \
             ' AND lang = %s' \
             ' AND type = %s'

Revision history for this message
Damián Soriano (damiansoriano) wrote :

I include Vo Minh Thu and Olivier Dony since they committed the unaccent() support in launchpad. They may better understand the implication of this changes in the code.

Revision history for this message
Damián Soriano (damiansoriano) wrote :

There is any news regarding this bug??

I don't know why it is still undecided, the problem seems really clear and easy to test. Also the solution should highlight the problem here.

Is there any way I can contribute to fix this in the server?

Revision history for this message
Damián Soriano (damiansoriano) wrote :

This bug has been reported like 40days ago, it seems to me a very important one since countries that use accents are unable to search some stuffs. Also I already point out a possible solution, that will take 5 mins to implement.

Is there any way I can accelerate this process? Is it feasible I propose a merge for the core of OpenERP? (I already propose meges in addons but when unnoticed)

Revision history for this message
Damián Soriano (damiansoriano) wrote :

Sorry Olivier Dony I made a merge proposal but I had an incorrect indentation. I delete the previous merge proposal, correct the indentation and redid the proposal.

I am not sure how to finish the merge and what I have to wait for, so the bug is fixed correctly in the nightly build, can you give me some hints?

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hi Damián,

Thanks for reporting the bug with great details and taking the time to submit a patch!

> Sorry Olivier Dony I made a merge proposal but I had an incorrect
> indentation. I delete the previous merge proposal, correct the indentation
> and redid the proposal.

No problem, though in general there is no need to delete and re-create a merge proposal, as they are automatically updated whenever you modify the proposed branch.
I also manually linked your branch with the bug because the link was not created automatically (you probably forgot to tag your commit with `--fixes`. See also [1] )

> I am not sure how to finish the merge and what I have to wait for, so the
> bug is fixed correctly in the nightly build, can you give me some hints?

You don't need to do anything else. Thu did the original implementation, so he will review your patch soon, and he will give you feedback on the merge proposal. He will also assess the risk/benefit ratio of the patch, to see whether it can be applied on the 6.1 stable branch safely [2].

Thanks for your contributions!

[1] For all the gory details regarding merge proposals and how to make them, see the documentation (there's a complete example including --fixes): http://doc.openerp.com/v6.1/contribute/15_guidelines/contribution_guidelines.html

[2] See the OpenERP Bug management policy: http://doc.openerp.com/v6.1/contribute/11_bug_tracker.html#bug-management-policy

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Low
milestone: none → 6.1
status: New → Confirmed
Revision history for this message
Vo Minh Thu (thu) wrote :

Thanks for the bug report and the merge prop. I've added a new merge prop. correcting a small mistake you made, and it should make its way to a new 6.1 build.

Revision history for this message
Damián Soriano (damiansoriano) wrote :

Grate, thanks Thu!

It will be released in an upcoming nightly build?? (I still don't understand perfectly which is the code that generates the nightly build)

Revision history for this message
Damián Soriano (damiansoriano) wrote :

Thu, the merge propose that solve this problem has not been committed yet right?

You know if this will take much longer?

BR

Damián

Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

Fixed in 7.0 via revid 5268 <email address hidden>

Changed in openobject-server:
milestone: 6.1 → 7.0
status: Confirmed → Fix Released
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.