As I move into Drupal 7, I'm suddenly very confused about something that I thought I understood (or didn't need to understand in the considerable amount of time I've spent in Drupals 5 and 6 --

I'll be working on a module and, in the process of developing the code, I'll throw in a few calls to dsm() and/or drupal_set_message(), perhaps in node--something.tpl.php or in a function that gets called from the template file. In my previous work, these calls always worked the way I expected -- on the next page submission, I'd get the results of the dsm's. In Drupal 7, I'm doing the same thing, but am finding that they're showing up one page too late -- I have to refresh the page to see them. In trying to figure this out, I began to think that the Drupal 7 page rendering model is that the selected page template gets evaluated and then -- and only then -- does the node being displayed on the page get loaded and rendered. Sure enough, a few tests with watchdog() and sleep() confirm this -- on one of my Drupal 6 sites, the node template file is run before the page template file, but, on my Drupal 7 site, the page template file is run before the node template file. This is with only-very-slightly changed versions of the standard D7 page template, and no funky tweakings of internal D7 behavior, btw, and I'm doing nothing special with caching -- all of the caching options on Config > Development > Performance are turned off.

This explains the message behavior I'm seeing in D7, but it really seems like the wrong thing -- I want those messages to appear as part of the immediate rendering of the page like they do on my D6 sites, not on a refresh of the page. This isn't just a matter of debugging convenience; it's also messing up some form validation code, where the validation error doesn't appear on the page produced by the form submission.

Or so I think, anyway. Does anyone know what's going on here? Was there a change in D7 that led to this seemingly new behavior, or have I somehow screwed something up on my site? I'd be happy to throw some debugging code into my sites if someone can point me in the right direction. Many thanks for whatever clarifications might be out there....