I have a hierarchical taxonomy of locations (country, state/province, city) which I'm displaying in a facet. It's showing the lowest level (city) correctly, but nothing other than that. The "Expand hierarchy" checkbox is ticked, and "Flatten hierarchy" is set to No, so I'd expect it to be showing all three levels - or am I misunderstanding this?

Comments

adam_b’s picture

StatusFileSize
new17.51 KB
new15.39 KB

more screenshots...

drunken monkey’s picture

Category: bug » support
Status: Active » Fixed

Please use the "Index hierarchy" data alteration to index all parent terms of a taxonomy term.

adam_b’s picture

Status: Fixed » Active

Tried this, but I get an error when I try and re-index the content: "The website encountered an unexpected error. Please try again later."

The only serious PHP error in the logs is
EntityMetadataWrapperException: Unable to get the data property parents_all as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of /var/www/html/sites/all/modules/entity/includes/entity.wrapper.inc).

The taxonomy is generated by http://drupal.org/project/location_taxonomize if that helps?

dynamicdan’s picture

Project: Search API Database Search » Search API
Version: 7.x-1.0-beta2 » 7.x-1.2
Component: Miscellaneous » Framework
Category: support » bug

I just tried to do something similar and got the exact same message.
I have the latest entity API version.

I'm not using any special taxonomy plugins. I have a regions taxonomy that has tags like Global -> Australia -> Victoria -> Melbourne

Either 'Index hierarchy' doesn't work or there is perhaps a requirement that all terms must have a parent?

dynamicdan’s picture

Title: "Flatten hierarchy" config doesn't do anything? » Index hierarchy data alteration causes EntityMetadataWrapperException

Note that my setting on the workflow tab for search_api was 'All parent terms'.

dynamicdan’s picture

Title: Index hierarchy data alteration causes EntityMetadataWrapperException » Cannot display hierarchical taxonomies as options due to Index hierarchy data alteration causing EntityMetadataWrapperException

Hmmm.. better title needed to reflect original issue. Perhaps also another issue should be created.

travisc’s picture

Same issue using

Index hierarchy data alteration to index all parent terms of a taxonomy term.

EntityMetadataWrapperException: Unable to get the data property parents_all as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of sites/all/modules/entity/includes/entity.wrapper.inc).

edit: eh, never mind

grasmash’s picture

I'm also experiencing this problem

@travisc Did you fix the issue? If so, how?

alanom’s picture

Same issue as dynamicdan with a very similar case (regions taxonomy with nesting around 4 levels deep, set to Index Hierarchy - all parent terms). Curiously, it worked fine until I cleared the vocabulary and then added a few hundred new terms.

If anyone knows what causes this or has fixed it, it would be appreciated if they could share it.

In my case I'm using Taxonomy Edge module to make the hierarchy work more smoothly, but as no-one else has mentioned that module it sounds like it's unrelated.

A potentially relevant note - this happens during the indexing of specific content, not any content. It can index some batches and falls over on others. Not yet figured out anything meaningful about which cause it to fall over. Edit: I think (not confirmed) it's terms with both parents and children that cause it to fall over. My content with a term with no parents or children in a vocabulary where most other terms have one or both has indexed fine without this error.

alanom’s picture

Priority: Normal » Major

Well, I've found one cause of this. It seems nothing actually stops to check if a term whose ID has been found in a field actually exists before trying to grab the parents.

When terms are deleted, fields that reference those terms just carry on sitting there like nothing happened, carrying the TID of a dead term, until the entity they are on is re-saved when they fail validation and finally fall off. So, if you've ever deleted a term that was used by being referenced in fields, unless you immediately loaded and re-saved all the content that referenced it, you'll get this error.

Hitting 'Save' on all my existing nodes fixed this for me in the short term (luckily it's a development version of a site without too much content). But that's only a temporary fix - as soon as a term that is in use is deleted, search indexing will fail again.

Unless there's something I've missed, I'd call that a major bug as deleting taxonomy terms is a standard Core behaviour, and here, a standard Core behaviour can cause a site's whole search feature to fail with server errors on indexing. People could easily launch production sites that seem stable, but where the search indexing will die a painful death when next indexed after a content editor innocently deletes a taxonomy term that is in use but no longer wanted or needed.

A proper fix will involve, at an appropriate point in the code, checking the term referred to in a term field actually exists before trying to get its parents. I don't know nearly enough about entity wrappers to know how to implement this, but the entity wrapper objects do contain the ID and information about type. I'd guess that the first foreach in extractHierarchy() in callback_add_hierarchy() would be a suitable place to do it.

Of course in an ideal world, the core Taxonomy (or, Entity) module would actually clean up reference fields when a term is deleted, but that's not going to happen any time soon. There's been an issue open on this matter for a year now, and, like almost every Core issue I've seen, most of the activity has been semantic arguments about whether it's a bug or not. There's a related contrib module at sandbox stage, so there has been some activity, but it doesn't look like they're really even past the "What approach is best?" stage yet. Based on my (limited) experience of Core issues I'd bet it won't be fixed in D7 Core before summer 2013 at the earliest.

(Of course, it's possible there's another cause as well. I'm seeing some other strange indexing issues - content not crashing but not indexing for unexplained reasons. Will add more info if I find anything useful...)

alanom’s picture

Title: Cannot display hierarchical taxonomies as options due to Index hierarchy data alteration causing EntityMetadataWrapperException » With Index Hierarchy data alteration, deleted terms cause indexing to crash with EntityMetadataWrapperException
alanom’s picture

Status: Active » Needs work
StatusFileSize
new1.15 KB

Here's a sticky-plaster patch that fixes the problem for me. All this entity wrapper stuff means little to me, so this is probably not the best or most efficient approach, but it works for me and hasn't noticeably affected indexing performance.

Someone with more experience with Search API and Entity API entity wrappers should get involved.

The source of the problem on Search API side for me is the call to $wrapper->$property->value in extractHierarchy() in includes/callback_add_hierarchy.inc.

This adds a simple check using entity_load() before preceding to check that, where it's a taxonomy term, that term actually exists. I'm guessing term being indexed have been or will get loaded into memory earlier or later on anyway, in which case that or this enitity_load call will simply get it from memory rather than hassling the database multiple additional times.

That said, there's probably a better way: but this seems to work for now.

Anonymous’s picture

Applied patch from #12, works for me. Thanks.

brephraim’s picture

Patch didn't apply to latest, but manually coding in the change worked. Thanks!

Anonymous’s picture

Is it possible to get the changes proposed by the patch in #12 into dev?

stockliasteroid’s picture

Patch works for me too, my indexing died with the same error...

Anonymous’s picture

Status: Needs work » Reviewed & tested by the community

Since this seems to work, please commit. Thanks.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, prevent_entity_error_on_deleted_terms.patch, failed testing.

esclapes’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.14 KB

Rerolled patch against current dev branch. Can also be applied to 7.x-1.3 without problems. Worked as expected.

giorgio79’s picture

Thanks patch worked for me as well.

mvc’s picture

#19 applies cleanly against 7.x-1.4 as well. thanks!

kubrt’s picture

Run into the same error after deleting some terms, applied #19 against 7.x-1.4 , all working fine again. Thanks for the patch and please commit.

giorgio79’s picture

Status: Reviewed & tested by the community » Needs review

The patch does not apply for me for 1.4

git apply 1594762-18-deleted-terms-cause-indexing-crash.patch
error: patch failed: includes/callback_add_hierarchy.inc:234
error: includes/callback_add_hierarchy.inc: patch does not apply
giorgio79’s picture

Status: Needs review » Reviewed & tested by the community

Scratch that. I already applied it once. :D Still works fine.

This patch also helps for simple hierarchical taxos, as hierarchy is not captured at all without this it seems.

Anonymous’s picture

Yup, applies cleanly to 1.4. Can we get this committed?

drunken monkey’s picture

Title: With Index Hierarchy data alteration, deleted terms cause indexing to crash with EntityMetadataWrapperException » Fix detection of deleted items in the Hierarchy data alteration
Component: Framework » Plugins
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new672 bytes

Sorry for taking so long to get back to you. While your solution seems to work fine, it's a bit to specific for my taste – the same could happen with any other entity, too.

The attached patch should fix this in a type-independent manner, instead of just for taxonomy terms. Please test/review and we can hopefully get this committed soon.

schnitzel’s picture

patch worked for me, had exactly the issue and now its indexing seamless

schnitzel’s picture

Status: Needs review » Reviewed & tested by the community
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Committed.
Thanks for testing, and thanks @ alanom and esclapes for your work!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

errev’s picture

Did not work for me
got the error

git apply 1594762-18-deleted-terms-cause-indexing-crash.patch
error: patch failed: includes/callback_add_hierarchy.inc:234
error: includes/callback_add_hierarchy.inc: patch does not apply

What the final folder should be?
Is it enity folder?

mvc’s picture

@errev: the patch was already committed. just download the latest dev version and it will be included.