zopefoundation / Products.ZCatalog

Zope's indexing and search solution.
Other
5 stars 22 forks source link

"ValueError: too many values to unpack" when querying indexes with more that one _ #114

Closed agitator closed 3 years ago

agitator commented 3 years ago

While updating a Plone 5.0.4 site to 5.2.3 I ran into this Error

  Module plone.api.content, line 664, in find
  Module Products.CMFPlone.CatalogTool, line 463, in searchResults
  Module Products.ZCatalog.ZCatalog, line 625, in searchResults
  Module Products.ZCatalog.Catalog, line 1091, in searchResults
  Module Products.ZCatalog.Catalog, line 634, in search
  Module Products.ZCatalog.Catalog, line 562, in _search_index
  Module Products.ZCatalog.query, line 91, in __init__
ValueError: too many values to unpack
....

(Pdb++) request
{'prioritization_lv1_effective': datetime.datetime(2021, 1, 22, 14, 6, 8, 965079), 'allowedRolesAndUsers': ['Anonymous', 'Authenticated', 'Manager', 'user:admin'], 'sort_on': ['effective'], 'sort_order': 'reverse', 'prioritization_lv1': True}
(Pdb++) field
'prioritization_lv1_effective'
(Pdb++) field.split('_')
['prioritization', 'lv1', 'effective']

Looks like the changes in https://github.com/zopefoundation/Products.ZCatalog/commit/64b1f3ba7ae1e598e65006d68e6f1d8258ae66b0 cause this error.

jensens commented 3 years ago

Probably an field.lsplit('_', 1) would fix it?

petschki commented 3 years ago

@jensens I think field.rsplit('_', 1) is the correct fix. Only the last part is allowed as index operator. But in @agitator 's case its also wrong, because he doesn't pass any operators to the index. The only way to get around this is to submit the query value as dict to skip the "underscore" logic ...

petschki commented 3 years ago

just found this open PR: https://github.com/zopefoundation/Products.ZCatalog/pull/79 ... if this gets updated with rsplit update: this PR solves this issue without rsplitbecause of field.split(iid + "_") ... more elegant

/cc @thet

icemac commented 3 years ago

Fixed in #116.