This is a tricky issue, we're having trouble diagnosing it even with a debugger and could use some help.
For some reason when a search index uses the content access processor, it causes 'forum_id' to get lost from the entity cache when a forum topic is created. When the page is rendered, it shows a notice about array_flip(). If you look in database, the node seems to be saved properly with the tid of the forum, but if you look at the cache_entity table the forum_topic node is missing the forum_id property.
Something seems to happen when the content access processor is enabled such that when the node is cached, it loses the forum_id properly. Perhaps something in hook_node_access_records_alter(), but I haven't been able to track down exactly when this is happening.
Recreating the issue
- Install Drupal using the "standard" install profile
- Enable the forum module
- Enable search_api_db
- Create a db server (you can also just enable search_api_db_defaults which immediately shows this issue)
- Create an index and add enable the content access processor
- Create a new forum topic and save it.
- You should see a notice about array_flip() any time you visit it.
- Clear the cache
- Visit the same forum topic page and the error will be gone
- disable the content access processor
- create a new forum topic, and there is no error
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2773803_4_invalidate_node_cache.patch | 636 bytes | drholera |
Comments
Comment #2
frankcarey commentedComment #3
drholera commentedChecking.
Comment #4
drholera commentedI think this is the cache issue. So I found solution, we can invalidate entity cache for added node right after trackItemsUpdated() method. In this case, errors don't appear. What do you think about this solution?
Comment #5
drholera commentedComment #7
borisson_Not sure if this is even the right solution, but shouldn't we use
Cache::invalidateTagsinstead? Not sure if that invalidates the same caches though.Comment #8
drholera commentedCache::invalidateTagswill work too, but I think invalidate cache that exactly we need is more correct instead of invalidating all cache records with required tag. But ve can useCache::invalidateTags(['node_values'])Comment #9
borisson_, the first argument to
Cache::invalidateTagsis exactly the needed cache tags, soCache::invalidateTags('node:' . $node->id()should do the same thing, this might invalidate more actual caches, but as far as I understand the cacheing layer, this is the preferred method.I'll let @drunken monkey decide though.
Comment #10
mpp commentedSee https://www.drupal.org/node/2784849#comment-11533091
Comment #11
drunken monkeyI just tested this and could indeed reproduce the problem from a clean installation, so this is definitely a problem. And a pretty weird one at that – no idea how this could happen. But such things seem to occur regularly now in Drupal 8 – a thousand pieces of code running through all parts of the page request, with no chance of following what's going on.
But still, I'd vastly prefer being able to find and fix the root cause here (might easily be a Core bug – so all the more important to find it) instead of applying a workaround.
Furthermore, the proposed patch doesn't even solve the issue. You still get notices on the first page view, and a missing forum breadcrumb until you manually clear the cache. (I couldn't reproduce the notices on subsequent page requests.) So it seems we either have to come up with a better workaround, or need to find the root cause after all.
Anyone fearless enough to try debugging this? Maybe use object marking or showing the object addresses to see whether you're actually dealing with two different node objects, and then find out where the second one comes from. Otherwise, you'd have to find out at which point the
forum_idfield gets removed from the node object – which, since (I think) this all happens through methods in theNodeclass, shouldn't be too hard.Comment #12
benstallings commentedI think we can safely say this is outdated.