Duplicate entries in search causing wrong result in search_count

Hello,
I am currently trying to debug a problem and need both mental and technical support :slight_smile:

The search in a model with a limit returns duplicate records, which of course are only displayed once. This means that the result of search_count does not match the number of unique results in search. Is this behavior normal and if not, how would you debug it? Perhaps someone has already had a similar problem and remembers a possible cause.

Its strange to have duplicated records, as the id field makes it unique per result.

I guess the problem is related to having some custom sql (probably and order clause) which does a join with another table and this duplicates the records.

If that is not the cause we will need more details on the search aand the fields used to give more info.

This (I’d add domain_xxx functions to the possible culprit).

Also, some duplicated translations may be present.

Finally, I’ve had cases where duplicate entries in Many2Many tables were causing this in ORM generated queries.

Thanks! It was indeed caused by order_fieldName. Needed to return a subquery which selects only one entry. :man_dancing:

I’ll leave this here in case anyone ever needs something like this. You can pass a subquery to the order method.

@classmethod
def order_number(cls, tables):
    pool = Pool()
    Other = pool.get('other')
    table, _ = tables[None]
    other = Other.__table__()
        
    subquery = other.select(
        other.number,
        where=(other.person == table.id),
        order_by=other.number,
        limit=1)
        
    return [
        Case(
            (subquery == None, SOME_FALLBACK),
            else_=subquery)]
1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.