Fixing Drupal error: Notice: Undefined offset: 1 in views_block_view()

Damn this was a pain. For more heads up go here: http://drupal.org/node/1065942

It's caused by stale records in the block table that then fail to resolve. There's plenty of reading material out there and suggested fixes etc. that I am sure work but once I knew what the problem was I applied *my process* for all Drupal problems like this.

  1. Find the code that issues the message..
  2. Trap the code and drupal_set_message() the offending item
  3. Use that information to fix-up the database / code as required.

Here's how the fix works for this particular problem. In my case I edited views.module, line 569, here's the code that was causing the notice to be show:

list($name, $display_id) = explode('-', $delta);

and here is what I added to the code to find out what the duff delta in question was...

if (count(explode('-',$delta)) == 1) {
  drupal_set_message($delta);
}
list($name, $display_id) = explode('-', $delta);

Simples. All I did then was refresh the page, take a note of hash value that was displayed and then cutting-and-pasting it into a command line MySQL session I issued this query:

mysql> delete from block where delta = 'd98a0bfa5a33e7d8bab0fc0670bdc9fd';
Query OK, 4 rows affected (0.01 sec)

Which took out all four problem pages at once.
Job done.

Don't forget to remove the line of code just in case it upsets users!
:)

Content Tags: 

Comments

Great "how to" ! You solved my issue in an impressive way ! I'm a newbie and still did it ! Thanks.

Thank you for this. I would never figured it out by myself.

Thanks for this - fixed the problem nice and easy!

You saved my day. Thanks for sharing this!

Your suggested fix worked beautifully when I ran into this same error.
Being new to Drupal, this was also fairly educational as to how things work underneath.

Thank you very much for posting such a concise, good fix.

You saved me hours of debugging with this simple SQL query! Thank you!

It worked immediately, but just in case it didn't, I actually ran a SELECT statement before your DELETE statement. I didn't need to revert, but safety first, am I right? :)

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <pre> <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Full HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.