Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I know personally been flooded with the same messages at several occasions because something didn't realize it'd be called multiple times in a page load and did a drupal_set_message. Most people just don't give it a thought.
I can't think of too many use cases for repeating the exact same thing multiple times on the same page, and the only reason I can think of is debugging (thus my why my patch sets the error.inc one to TRUE).
Comment | File | Size | Author |
---|---|---|---|
#25 | webkit-error-coalescing.png | 19.69 KB | Mark Trapp |
#17 | drupal_1428032_dsm_false_backport.patch | 1.57 KB | Pere Orga |
#3 | drupal_1428032_dsm_false.patch | 1.54 KB | hefox |
drupal_set_message_repeat.patch | 1.26 KB | hefox | |
Comments
Comment #1
kscheirerdrupal_set_message_repeat.patch queued for re-testing.
Comment #3
hefox CreditAttribution: hefox commentedComment #4
hefox CreditAttribution: hefox commentedComment #6
hefox CreditAttribution: hefox commented#3: drupal_1428032_dsm_false.patch queued for re-testing.
Comment #7
star-szrI like this. I found this looking for an issue about repeated messages with update.module (as below). I think that issue could be resolved here.
Comment #8
tstoecklerI somehow had in mind that the current default was for performance reasons. That's totally bogus, though. The difference is a single in_array() and since the function is not called that often, that is definitely negligible.
I totally like this patch, I guess it could use a couple more approvals though before RTBC. Code-wise it's perfectly fine. The change to _drupal_log_error() totally makes sense.
Comment #9
tim.plunkettMakes sense to me.
Comment #10
btopro CreditAttribution: btopro commentedwould it be helpful to know how many times a message was generated though for debugging purposes? I do find the current "show everything" policy annoying (especially with local development and php notices active) but knowing an error / message was generated multiple times could help debug faulty logic. Maybe tie it to a global defined value for the default so that other projects (like devel) could optionally switch it to default the other direction?
Comment #11
tstoeckler_drupal_log_error() explicitly sets $repeat to to TRUE, so for errors we still get that info.
Comment #12
hefox CreditAttribution: hefox commentedMy guess is that anyone that'd want to see a message repetitively would switch it to TRUE (dpm likely would come with it as TRUE out of box), there and a setting isn't needed
Comment #13
DamienMcKennaLooks good. +1
Comment #14
tstoecklerLet's go back to RTBC.
Comment #15
Dries CreditAttribution: Dries commentedThis looks like a better default to me to. Committed to 8.x. Thanks.
Comment #17
Pere OrgaI think we should backport it.
Comment #18
tstoecklerThe backport is sound.
Marking this RTBC to get it in David Rothstein's queue.
Usually we don't backport these types of changes to D7, but in this case, I cannot imagine that anyone reasonably *expects* the same error/message to appear multiple times. Hmm...
Comment #19
David_Rothstein CreditAttribution: David_Rothstein commentedI can definitely think of other situations where you expect the message to repeat.
For example, what about a very long form with more than one field that has the same name (maybe imagine two "address" or "phone number" fields that are part of two different field collections)? If there are errors in both, then it helps the user to see two separate error messages to indicate that, even if the text is the same.
I'm not sure if Drupal 8 wants to change the form API to deal with that (the above patch didn't, but reopen this if you think it should)...
But for Drupal 7, the fact that we already have a couple good use cases for the current behavior mentioned in this issue means (to me, at least) that there's really no good reason to change the default out from under people. The parameter exists and is well-documented; for anyone who wants to prevent repeated messages in their code, it's very simple to do that :)
Comment #20
Pere OrgaOk.
I entered that issue because of #1817680: Update notification is printed more than one time. For me at least, it was annoying to wait 3 days to upgrade to Drupal 7.16, seeing multiple warnings in every admin page. But yes, preserving some behaviors is probably important.
Comment #22
David_Rothstein CreditAttribution: David_Rothstein commentedI now think it should :)
And honestly think we should consider rolling this whole patch back? The primary effect of this change really seems to be that it hides bugs in the calling code. (If your drupal_set_message() is being called more than once on the same page request, there's a very very good chance it's because code that you don't expect to run more than once is erroneously running more than once anyway. And in the rare event where you really do expect it to run more than once, passing $repeat as FALSE is easy, but at least we force you to explicitly acknowledge that you expect that.)
Comment #23
hefox CreditAttribution: hefox commentedMy reason is that end user experience is much more important than developer experience in this case -- multiple of the same message is confusing and can flood the screen, and is very rarely desired.
> same page request
From what I've observed, usually it's not the same page requests (in d6 at least) -- hook_init + drupal_goto() + hook_init again. Since it's session based, messages can spam page loads/come from ajax/etc.
Comment #24
David_Rothstein CreditAttribution: David_Rothstein commentedHm, that is probably true.
Comment #25
Mark TrappI agree with David_Rothstein in that this potentially hides bugs, and am thankful this hasn't (yet?) been backported to Drupal 7.
I also agree that message flooding for the user is a poor experience, but what about a compromise? Playing off of btopro's comment in #10, instead of silently dropping the additional error messages, note the number of repeats in the error message. Something like:
This mimics how Safari/Chrome handle multiply-repeating messages in the console (they stick a grey number next to the error):
Comment #26
btopro CreditAttribution: btopro commentedSo from reading through a solution appears to have already been committed to D8 core; perhaps this can be reopened under a different issue if people are passionate enough about an additional change but that way this can be marked done and get something out of the D8 issue queue that's already been resolved (as per original request / design decision) :)