6093 comments
2357 subscribers
6240 on Twitter
Subscribe! Feed reader E-mail

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

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.

Short URL: http://sachachua.com/blog/p/5971
  • http://lisnews.org Blake

    “I jumped back to the last known-good revision”

    How do you have things set up that you can just jump back?

  • http://sachachua.com Sacha Chua

    I remembered the last known good revision well because I had put a bit of effort into making sure that our regression tests all ran (uncovering a number of bugs along the way). Once I figured out the revision number (it was #1947), I used svn update -r 1947 to go back to the revision.

    We test all of our updates against a copy of the production database and all the behavior-related changes are in the source code, so then it was a matter of stepping forward until I found what broke. I started stepping through it incrementally (without refreshing the database from scratch) because I thought that would save me time, but the error didn’t reappear. When I refreshed the database for each update, though… BOOM! turned out it was the very next revision. When I figured out which revision it was and what code was in that revision, it was MUCH easier to figure out what the problem was.

    The other approach is to figure out, based on the symptoms of the current system, what’s going wrong. I had tried that before starting to chase down revisions, and I didn’t get anywhere because the bug was nowhere I would’ve looked myself.

  • jmorahan

    As of Drupal 6, the {blocks} table has a regular old primary key, {blocks}.bid which you can use instead of the module+delta combination that is unfortunately still needed in D5.

  • http://sachachua.com Sacha Chua

    Someday I’ll get to join you folks in the 21st century! =) I can’t _wait_ to be able to take advantage of _menu_alter…

On This Day...

  • 2013: Emacs Chat: Carsten Dominik — In which Carsten shares how he got started with Emacs, the joys of Calc, and other cool things. =) Carsten [...]
  • 2010: Reflections on PresentationCampToronto — At Tuesday’s PresentationCampToronto organized by Chris Gurney, I gave an eight-minute talk on relentlessly improving your presentation skills. This was [...]
  • 2009: Drupal in the Trenches: Fighting with Views — The other developers have bought into the idea that all behavior-related changes should be in the source code. It’s the [...]
  • 2009: Upcoming Web 2.0 Conferences — Web 2.0 Expo – SF March 31 to April 3, 2009 (Schedule) San Francisco, CA Conference plus workshops: $1745 before March 30, $1945 [...]
  • 2009: Ada Lovelace Day linkfest and wrapup — Here’s a quick wrap-up of some posts from Ada Lovelace Day: Linda Rodriguez wrote about how Ada Lovelace Day came to [...]
  • 2009: Helping my parents learn more about Internet and business; any tips? — Last Sunday, my mom and I were talking about other businesses that she and my dad could explore. She’d recently [...]
  • 2009: Looking for female IT role models in Toronto? — Joey de Villa (Accordion Guy) has put together a great list of some awesome Toronto women in technology. I know [...]
  • 2008: Optimizing my day — Maybe there’s some truth to the advice, “Early to bed and early to rise makes a man healthy, wealthy, and [...]
  • 2007: Sunday tea and developing my personal style — You discover yourself through your choices. One of the things I like about having my own place is learning more about [...]
  • 2007: Tea — I picked up another teapot and a wooden box of assorted teas at Winners this afternoon in preparation for my second [...]
  • 2006: Speaking of The Miniskirt… — Lusine was surprised to find out that I’m taking my master’s in mechanical and industrial engineering. (I really should drop the “mechanical [...]
  • 2006: Noodle night — One of the wonderful things about Graduate House is that the Graduate House Council organizes a lot of social events. Tonight [...]
  • 2006: Where do network cards go to die? — I’ve rummaged through all of my things, and I’m certain I left my wireless network card in the Philippines. Mumble. That’s [...]
  • 2004: ACM Technews: “Search Beyond Google” — From ACM Technews: Google’s enormous success with its search engine—and its apparent inability to develop a follow-up innovation momentous enough to sustain [...]
  • 2004: Paolo’s first webcomic — Looks like Paolo Venegas is starting a webcomic!
  • 2004: Remembering — A friend and I were thinking of papers to submit to the Loyola Schools Review. I joked, “What could I write [...]
  • 2003: killer examples for computer science education — http://www.cse.buffalo.edu/~alphonce/OOPSLA2002/KillerExamples/
  • 2003: Computer Braille Code Reference Card — nabs-l@nfbnet.org, Wade Hemmelrick: This is a free listing of all the computer braille code symbols. Computer Braille Code Card in Grade 2 [...]
  • 2003: python web solutions — python@lists.free.net.ph, Andy Sy: http://www.python.org/cgi-bin/moinmoin/WebProgramming
  • 2003: Emacs test suite — Robert Anderson has some testing scripts at http://rwa.homelinux.net/emacs
  • 2003: Chinese Python? — Miguel Paraz, python@lists.free.net.ph: http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html The author claims that Python is easy to translate to Chinese. This could be useful to the Chinese-literate people [...]
  • 2003: [[ComputerScienceCurriculum2002-2003]] — Finished encoding the ComputerScienceCurriculum2002-2003. Whew!
  • 2003: Summary of G. Polya’s “How to Solve It” — education — http://www.math.utah.edu/~alfeld/math/polya.html Local copy: PolyaHowToSolveIt
  • 2003: Free mailing lists — Tech mailing lists without a home might want to check out http://www.freelists.org .
  • 2003: Nemeth mathematics — On the blindprogramming@yahoogroups.com mailing list, Yvon Provencher mentions the useful tutorial at http://www.freedomscientific.com/fs_downloads/notenemeth.asp .
  • 2003: emacs-wiki-markup-word — I use (defun emacs-wiki-markup-word ()) to squelch all the bad markup I’m getting lately.
  • 2003: equals in URLs and emacs-wiki.el — I suspect that URLs need to be verbatim; stray equal signs and underscores can be their undoing! Maybe I should just [...]
  • 2003: solition paper — Cross-reference: CoastLog#1
  • 2003: magicpoint — Chris Beggy writes in with another tip (thanks!). Chris thinks that Magicpoint is an excellent PowerPoint replacement. I like Magicpoint’s text-based presentation files [...]
  • 2003: pdf presentations — On debian-user@lists.debian.org, David Z Maze thinks Prosper is great for making PDF presentations from LaTeX. xpdf -fullscreen -papercolor black to actually run [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!