Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Sorting widget breaks on missing indices #78

Closed
cewing opened this issue Dec 5, 2015 · 2 comments
Closed

The Sorting widget breaks on missing indices #78

cewing opened this issue Dec 5, 2015 · 2 comments
Labels

Comments

@cewing
Copy link

cewing commented Dec 5, 2015

When an index which belongs to a field returned by the call to portal_atct (tool.getEnabledFields()) is not actually present in the portal_catalog, the criteriaByIndexId method breaks on attempting to retrieve the index object from portal_catalog.

Such a circumstance can arise, for example, if you install alm.solrindex which by default deletes text indexes such as Title and Description and gives over indexing those fields to solr. The line of code linked above throws a key error which then prevents the widget from rendering at all.

One possible fix is to wrap the lookup in a try...except clause like so:

    def criteriaByIndexId(self, indexId):
        catalog_tool = getToolByName(self.context, 'portal_catalog')
        try:
            indexObj = catalog_tool.Indexes[indexId]
        except KeyError:
            return ()
        #...

It seems like, so long as the index is not present in the catalog, there would certainly be no criteria associated with it that would be valid, so returning an empty iterable maintains the contract of the method while protecting against this edge case.

@avoinea
Copy link
Member

avoinea commented Dec 7, 2015

Can you please add a pull request with the working code?

tnx.

@avoinea avoinea added the Bug label May 19, 2016
avoinea added a commit to collective/eea.facetednavigation that referenced this issue Jul 22, 2016
@avoinea
Copy link
Member

avoinea commented Jul 22, 2016

Fixed.

@avoinea avoinea closed this as completed Jul 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants