Skip to content

catalog query with sort_on="start" gives wrong order #1

@vincentfretin

Description

@vincentfretin

I know two places where you have sort_on="start" in a catalog query in Plone, in events and calendar portlets.
I have a events portlet in a production site with start index of type DateRecurringIndex.
I randomly see the events in the wrong order.

My guess is that the result.sort() line at line 738 in Products/ZCatalog/Catalog.py
doesn't work with the values from DateRecurringIndex._unindex which are IISet.

With DateIndex, result contains:

[(1078236420, -208989251, <bound method Catalog.__getitem__ of <Products.ZCatalog.Catalog.Catalog object at 0x85f2b90>>), (1077970020, -208989249, <bound method Catalog.__getitem__ of <Products.ZCatalog.Catalog.Catalog object at 0x85f2b90>>)]

with DateRecurringIndex, result contains:

[(IISet([1077998820]), 1208154628, <bound method Catalog.__getitem__ of <Products.ZCatalog.Catalog.Catalog object at 0x81d5488>>), (IISet([1078236420]), 1208154629, <bound method Catalog.__getitem__ of <Products.ZCatalog.Catalog.Catalog object at 0x81d5488>>)]

I think the comparison of two IISet is undefined. I didn't find any cmp in the code.

The solution is maybe to implement the documentToKeyMap method and return a fake object implementing getitem which return the first element of the sorted IISet...
ah no, that's not right if you have recurrence. I really don't know.

For now, I simply monkey patch the events portlet renderer to sort the date a posteriori.

results = catalog(portal_type='Event',                                      
               review_state=state,                                          
               end={'query': DateTime(),                                    
                    'range': 'min'},                                        
               path=path,                                                   
               )                                                            
#                   sort_on='start',                                            
#                   sort_limit=limit)[:limit]                                   
return sorted(results, key=lambda x: x.start)[:limit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions