The new revision gets saved as the old bundle, when external cache systems are used

Created on 9 April 2025, 10 days ago

Problem/Motivation

I used the module on a site that uses the memcache module , to convert some nodes from bundle A to bundle B. After the process finished, although all the revisions of the node (both on base tables, and on field tables) got converted to B, when the new revision got saved, it got saved again as bundle A. Also in the log message of this revision there was written "Converted from A to A."

I have noticed also other cache problems, not related to convert_bundles, which I haven't yet debugged, clearly memcache has some issues on cache invalidation.

I see that addNewFields calls drupal_flush_all_caches() in the beginning, which should be enough when the entity is loaded later. But because of the insufficient cache invalidation on memcache, the entity gets loaded on its old status, so it gets loaded as bundle A, and the new revision is created and saved again as bundle A.

Steps to reproduce

The description should be enough to explain how to reproduce, but there is a problem: The bug is random. It doesn't happen every time.
It never happens when the default db cache is used.
It definitely has to do with using external systems (like memcache) for caching. It might have to do with bugs on the memcache module, or the memcache library, or the memcache extension, or the memcached itself, or it could also be a generic issue when external caching systems are used.

Proposed resolution

I have an open question whether calling drupal_flush_all_caches() at the beginning is too hard and should be removed, but this is irrelevant here. Let's keep it as it is for now.

But I propose to use the core's resetCache function, as an extra step before loading the entity in the addNewFields operation. That way, even if the flushing of caches did not complete successfully (which, of course, is NOT convert_bundle's responsibility), at least we instruct the core to load the entity completely uncached, directly from the database, which is anyway the intention.

Remaining tasks

Review.

User interface changes

-

API changes

-

Data model changes

-

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇳🇴Norway efpapado

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024