"Notice: Undefined index: data in views_plugin_cache->restore_headers()" appears on 2 lines of
plugins/views_plugin_cache.inc.

Error message detected with php 5.4 and 5.3

Comments

naoliva’s picture

following

drvdt’s picture

+1

david_garcia’s picture

+1

david_garcia’s picture

+1

david_garcia’s picture

StatusFileSize
new989 bytes

The same change needs to be done in line 233, yet I believe these changes may be hidding the true root of the problem.

k.skarlatos’s picture

Hello, i have got the same problem, but with slightly different lines.

Notice: Undefined index: data in views_plugin_cache->restore_headers() (line 242 of /var/www/clients/client1/web2/web/sites/all/modules/views/plugins/views_plugin_cache.inc).
|Notice: Undefined index: data in views_plugin_cache->restore_headers() (line 236 of /var/www/clients/client1/web2/web/sites/all/modules/views/plugins/views_plugin_cache.inc).

PHP 5.4.20 (cli) (built: Sep 18 2013 19:55:33)
MariaDB Server 5.5.33a-MariaDB-log
Drupal 7.23
Views latest 7.x.3.x-dev from git

patch #5 fixes it for me, but i guess it needs to be rerolled so it can work from inside the views folder so it can apply cleanly (it must refer to plugins/views_plugin_cache.inc not /views/plugins/views_plugin_cache.inc).

Anonymous’s picture

StatusFileSize
new977 bytes

I rerolled the patch and tested on my local and it works nicely with make files now.

Renee S’s picture

Works for me, thanks!

gapple’s picture

Marked #2083151: Cache plugin, Undefined index 'data' as a duplicate, but it contains a better patch in #5:
- To follow coding standards, curly braces should always be used
- !empty($args['data']) is simpler than is_array($args) && isset($args['data'])

johnv’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new864 bytes

Attached is the pach from #2083151-5. It has better code style.

Status: Needs review » Needs work

The last submitted patch, 10: views_2018737_10 undefined_index_data.patch, failed testing.

johnv’s picture

Status: Needs work » Needs review
Related issues: +#2083151: Cache plugin, Undefined index 'data'

That many errors? That cannot be true. Retest.

The last submitted patch, 5: views_plugin_cache.inc_.patch, failed testing.

The last submitted patch, 7: 2018737-views_plugin_cache-10.patch, failed testing.

Exploratus’s picture

Same here.

bbujisic’s picture

Patch at https://drupal.org/comment/7905923#comment-7905923 appears to be working. Maybe we should consider reopening that thread and closing this one?

johnv’s picture

@Branislav Bujisic, the patch you mention is already copied to this issue (in #10).

tamonten1’s picture

subs

johnv’s picture

Status: Needs review » Needs work

The last submitted patch, 10: views_2018737_10 undefined_index_data.patch, failed testing.

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new2.38 KB

The proposed patch is not the right approach. The PHP notice is correct that something is wrong in the stored JS/CSS as they are incomplete (missing the "data" key for example). The problem is in views_plugin_cache::gather_headers(), which populates the storage with a broken array diff. The function uses drupal_array_diff_assoc_recursive() which can return partial arrays, but we always want complete CSS/JS definition arrays.

We cannot use array_diff_key() instead since we also want to check if the value (the JS/CSS definition array) is different.

So I propose to use a helper method to cleanup the diff array after drupal_array_diff_assoc_recursive() (which was introduced in #1511396: php 5.4 and "Notice: Array to string conversion"). That way we can throw out entries where only the JS/CSS weight is different.

Patch attached.

Status: Needs review » Needs work

The last submitted patch, 21: views-asset-diff-2018737-21.patch, failed testing.

klausi’s picture

Version: 7.x-3.7 » 7.x-3.x-dev
klausi’s picture

Status: Needs work » Needs review
j_byrd’s picture

Anonymous’s picture

patch #21 worked for me: notices are gone: no other issues.
Environment: Latest drupal, UC shop, a lot of cached and non-cached views pages and views blocks, APC, Varnish, memcache.

tamonten1’s picture

patch # 21 work for me

anybody’s picture

Works for me too. RTBC?

maximpodorov’s picture

Status: Needs review » Reviewed & tested by the community

RTBC!

maximpodorov’s picture

There's a small typo: $diff_funtion instead of $diff_function. But this does not affect the functionality.

cameron prince’s picture

#21 works well for me with latest release version of views.

Anonymous’s picture

cmedina’s picture

#21 works well for me.

wolfshine’s picture

#21 worked on 7.x-3.8

Ravenight’s picture

#21 worked for me

oriol_e9g’s picture

Same notice with PHP 5.3 and #21 works

oriol_e9g’s picture

StatusFileSize
new2.39 KB

Small typo #30 fixed

alesr’s picture

Patch from #37 (same as #21 with a fixed typo noted in #30) + clear cache did fix the problem.
RTBC++

oriol_e9g’s picture

Issue summary: View changes
toddtomlinson’s picture

I applied both patches in 21 and 37 and the error goes away but functionally the view is broken. I'm using views to display a list of products from Drupal Commerce. When I add an item to the cart its an ajax action and with the patches applies I don't get the error - but I also don't get anything added to the cart. Without the patches the first item is successfully added to the cart, but subsequent add to cart activities throws:

Notice: Undefined index: data in views_plugin_cache->restore_headers() (line 242 of /srv/bindings/46ab388bab8443b783b8a5b40d3c9c0c/code/profiles/panopoly/modules/contrib/views/plugins/views_plugin_cache.inc).

The view is cached, without caching this view everything works perfectly. Not sure if this is a commerce product issue (add to cart) or a views caching issue, but listing here since people have reported the same error.

agileadam’s picture

#37 worked for me as well.

killua99’s picture

RTBC++ I didn't find the error that @toddtomlinson describe, I'm not using Drupal Commerce so could have some relation.

Patch #37

ofry’s picture

I have this bug in Views 3.8.

quantos’s picture

Installing Views 7.3.8 has also introduced the bug for me too on a multisite stack. Drupal 7.28 already applied. No Commerce in the site. I'm only getting the Notice on one of the multisite sites (which uses a cached XML share feed View). PHP 5.3. Not sure what we can do. Can we roll back to previous version of Views meantime or can we turn off and ignore the Notice meantime?

Q.

Anonymous’s picture

#37 works, thank you !

zabelc’s picture

I just applied #37 against views-7.x-3.8, and it cleared up my error.

silurius’s picture

Odd. I applied #37 against my views-7.x-3.8 and (after clearing caches) the error persisted. So I'm back on 7.x-3.x-dev.

shi99’s picture

Applied patch #37 on views-7.x-3.8, cleared the caches and it fixed the error notice I was getting.

Thanks.

mandreato’s picture

Applied #37 on Views 7.x-3.8. The error went away.

silurius’s picture

Confirming that the patch works also for the 2014-Jul-12 version of 7.x-3.x-dev, but I still can't get it to work for 7.x-3.8 for some reason.

W.M.’s picture

@silurius

Which PHP version are you using? Thanks.

W.M.’s picture

I have updated to latest Drupal 7.30 and currently using View's dev ver. from Jul 23. No need to patch anything. The error problem went away. I am using PHP 5.5 / Apache on Windows 8.

silurius’s picture

@W.M., I'm on PHP 5.4.12 and was running Drupal 7.26 and just upgraded to 7.30. The error appears only on one of two twin load-balanced servers, which is odd.

joaogarin’s picture

Patch #37 fixed it for me in views 7.x-3.8

benjaminarthurt’s picture

#37 corrected the issue for us as well.

ispardillo’s picture

#37 works for me with Drupal 7.31 and views 7.x-3.8. Thank you very much.

tobiberlin’s picture

With patch #37 I got the following errors and WSOD:

	Notice: Undefined variable: array_mapping_func in views_plugin_cache->gather_headers() (Line 206 of /sites/all/modules/views/plugins/views_plugin_cache.inc).
SilviuChingaru’s picture

Patch from #37 works as expected.

haggins’s picture

Confirming patch #37 is working

kopeboy’s picture

can this be included pls? I hate to have errors and notices around for no real issues..

mxt’s picture

Patch provided in #37 works for me.

Please commit this.

Thank you very much

SilviuChingaru’s picture

Status: Reviewed & tested by the community » Needs work

Still got same error with #37 applied... :-(

mike stewart’s picture

Searched for same errror as indictated in #2018737: Notice: Undefined index: data in views_plugin_cache->restore_headers() and led me to this thread (top of search results). I tried the patch in #37 and it didn't help.

I was using a view with draggableviews and ran into this. Don't recall the steps that caused it. However, later in my workflow I built a feature with the same view which led me to: #1363458: Using an Exported a Draggable View does not work.

Ultimately I rebuilt part of the view by removing and re-adding the draggableviews field and sort weight which resolved the problem. I hope it helps someone else with this error. But doesn't seem to be the same problem/culprit that most others are encountering, since this is the only mention of draggableviews in the thread.

k.dani’s picture

patch in comment #37 works for me. thanks!

haggins’s picture

Patch #37 also works on a second site.

kclarkson’s picture

Status: Needs work » Reviewed & tested by the community

#37 worked great for me as well.

Exploratus’s picture

Works for me. Commit?

ofry’s picture

Status: Reviewed & tested by the community » Needs work

Are you tested it in dev version of Views? I think this patch needs reroll.

davidneedham’s picture

Status: Needs work » Reviewed & tested by the community

I applied the patch in #37 to the latest dev of views, and it applied cleanly. It seems to resolve the issue. Since several people have said it works previous to my post, I'm marking as RTBC.

anybody’s picture

I can confirm the patch works great. RTBC +1 ;)

geresy’s picture

Worked for me. + 1

sashken2’s picture

Patch #37 works good. RTBC +1

steveoriol’s picture

Pacth #37 works for me too... with PHP 5.6.1

oriol_e9g’s picture

lmeurs’s picture

Thanks for the patch, works for me!

@All for whom the patch did not work: did you empty all caches after applying? Flushing Views caches only is not sufficient since it does not clear the cache_views_data table.

Background info: the Views cache plugin initially stores a full JS array returned by drupal_add_js() so it can later compare it recursively with the at that time current version of the JS array. The problem lies within drupal_add_js() which always adds a small float to the weight so javascripts with the same weight will be loaded in the same order as they were added to the JS array, see drupal_add_js():

  // Tweak the weight so that files of the same weight are included in the
  // order of the calls to drupal_add_js().
  $options['weight'] += count($javascript) / 1000;

If a script has a weight of 0 and is added as the 15th script, it's weight will become 0.015. If the same script is added again later on during the same page call and in the mean while 2 other scripts have been added, it's weight will become 0.017. This difference is noticed by views_plugin_cache::gather_headers() using drupal_array_diff_assoc_recursive() which adds an array to the diff array for this script with only the weight element. The array has no data element, hence the PHP warning.

The patch from #2018737-37: Notice: Undefined index: data in views_plugin_cache->restore_headers() seems to work great by removing script arrays which only contain a weight element.

fakir22’s picture

Thanks! #37 worked for me after a clean cache (all)

kopeboy’s picture

Can we have a stable release?

jelo’s picture

#37 worked for me.

Anonymous’s picture

I'm getting this same error with the latest version of Views (7.x-3.10).
Wouldn't the patch in #37 already be included in that?
(Yes, I've cleared my cache several times.)

rodrigoaguilera’s picture

This patch is not commited to any views branch AFAIK

perignon’s picture

Deja Vu... Almost one year ago I was applying this same patch. So when is this going to get into views? v3.10 was just cut this week for a security issue.

bmunslow’s picture

I can confirm as well the patch did NOT make it into 7.x-3.10 ... re-re-patching.

jaydee1818’s picture

Confirmed - also needed to re-patch after security update.

shi99’s picture

Confirming that the patch in #37 works for me too.

jstoller’s picture

Patch in #37 works for me.

danbarron’s picture

#37 did not fix this for me. I did clear all caches, multiple times.

Drupal 7.34
Views 7.x-3.10

perignon’s picture

Priority: Normal » Critical

This bug needs to be squashed. Lets elevate this to a critical issue because there have been so many of us that have to keep re-patching views ever time a new version of views is released. It's a simple patch with multiple people reporting success in production environments. This is read to be committed. Please commit or report a reason it should not be.

misthero’s picture

confirmed working.. please commit

Drupal 7.34
Views 7.x-3.x-dev

Anonymous’s picture

Patched views again with #37: works perfect: please commit

Drupal 7.34
Views 7.x-3.10

anybody’s picture

+1 for commit and consideration in next stable release to get this away :)

Exploratus’s picture

37 worked for me. Every time I install a new site I need to remember to apply this patch. Commit? :)

rodrigoaguilera’s picture

To avoid that problem I use a drush make file to download all the modules with the patches I need

d0t101101’s picture

+1 - Hope to see the patch included in #37 included in the next major release. This really makes our sites fly, without errors!

zerolab’s picture

Have been using #37 on a large university website. Works like a charm!

  • dawehner committed 3e64a92 on 7.x-3.x authored by oriol_e9g
    Issue #2018737 by oriol_e9g, johnv, david_garcia, klausi, forgenator:...
dawehner’s picture

Thank you for your patience.
Committed to 7.x-3.x

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

.

anybody’s picture

Is it possible to have this in the next stable release too? The message is really annoying.

dmegatool’s picture

Just patched my site. Everything is fine and the error is gone. Hope this can make it to the stable release so when Views gets updated, I won't need to reapply the patch.

jstoller’s picture

@Anybody and @dmegatool: this patch has already been committed to dev, which means it will be included in the next stable release of Views. In the mean time, you can either manually patch 7.x-3.10, or install 7.x-3.x-dev.

dmegatool’s picture

I didn't know that if something make it to the dev version it will absolutely get on the next stable release. Thought it was more of a testing process. It sure looks like everything is fine but I guess if someone would find something, it would get pulled.

Anyway I'm cool with my patched 3.10. Thanks for the clarification.

jstoller’s picture

@dmegatool: The dev release just represents the latest commit in the 7.x-3.x git branch. Patches are generally only committed after they have been reviewed and tested by the community. Then at some arbitrary point in the future, assuming no more problems are found, the maintainers will tag a commit as the next stable release, but that all happens along the same branch used for development.

Status: Fixed » Closed (fixed)

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