Drupal gotchas: Never ever ever use anything less than module AND delta to specify blocks

| drupal

One of the common mistakes I run into is people not specifying enough information when deleting or updating entries in the {blocks} table. You should always use module AND delta to identify the block you’re working with. Delta by itself is not enough, and title is right out.

I learned this the hard way when my blocks suddenly started failing. I jumped back to the last known-good revision, and then stepped forward. All the update functions ran okay, one after the other. When I ran all the update functions after a database refresh, though, things failed. It turned out that another developer had changed the title of a block to a blank string, but left a db_query(“DELETE FROM {blocks} WHERE title=’%s’, $title”); in the function. And since it was called fairly early in our update cycle, it didn’t turn up during the incremental updates from my known-good database.

That took me about 45 minutes to find and fix. Thank goodness for tests and version control!

LESSON: Never ever ever use anything less than module AND delta to specify blocks.

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.