plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
255 stars 191 forks source link

FieldIndex on values of None should unindex #3064

Closed ewohnlich closed 9 months ago

ewohnlich commented 4 years ago

This bug was initially reported here: https://community.plone.org/t/fieldindex-does-not-update-when-field-updated-to-be-empty-value/11929

When value used for a FieldIndex is None, the indexer will not index it because a value of None is not supported. However if it previously had a value, the result is that the index retains this old value.

I think that the logic here https://github.com/zopefoundation/Products.ZCatalog/blob/5.0.1/src/Products/PluginIndexes/unindex.py#L253 is probably not quite right in that if it yields a value of None (not supported) it simply returns. It should probably also unindex before returning, if applicable.

I've only tested this with FieldIndex, not other subclasses of UnIndex.

What I did:

Create a Dexterity content type with schema consisting of

pmid = schema.TextLine(
    title=_("PubMed ID"),
    default='',
    required=False,
)

Create a FieldIndex 'pmid'. Create this content and set some value for pmid, say "1". Edit the content to empty this field.

What I expect to happen:

The pmid index should have no entries.

What actually happened:

The pmid index still has an entry of "1" for my content. As a separate issue, Dexterity should probably be saving my content with a value for pmid of '' per the default, not a value of None.

What version of Plone/ Addons I am using:

5.2.1

wesleybl commented 9 months ago

Fixed in: https://github.com/zopefoundation/Products.ZCatalog/pull/103