Drupal Filefield module bug (and other modules using AHAH form). “This form was missing from the server cache”

2011
Drupal Filefield module bug

Drupal Filefield module bug (and other modules using AHAH form). “This form was missing from the server cache” error by cache_get() bug. There is annoying bug when using the Filefield module in Drupal. If you previously uploaded a file and have site cache enabled you probably will see the following error message “An unrecoverable error occurred. This form was missing from the server cache. Try reloading the page and submitting again”.

This happens if you have enabled the site caching and set up the minimum cache lifetime.

The reason is drupal’s cache_get() function has a strange condition which causes the problem.

Here is a small amend that works. It affects anything that calls cache_get() function. So make sure you do a backup first.

includes/cache.inc

Change Ln 42

From

if (isset($user->cache) && $user->cache > $cache->created) {

To

if (isset($user->cache) && $user->cache > $cache->expire) {

The reason to do this is because Filefield is using AHAH for dynamically expanding its form field. Generally, AHAH’s CALLBACK function will retrieve the form from the cache_form table. When the cache lifetime is not set, Drupal won’t check whether the cache is expired or not and it will always generate the form from the cache. Thus, the above scripts will never be checked.

Once the cache lifetime is set, Drupal does check the cache eligibility but the condition doesn’t make sense. User access time ($user->cache) will be always greater than form cache created time ($cache->created).

Hey Richard, Thank you so much for this informative article. It saved my day...

by , Dec 24, 2014 at 10:09 am

Leave a comment