Since generating a 404 page calls drupal_get_messages(), if an HTML page contains any broken resources / images the hidden 404 will swallow the messages and prevent them from displaying on the page.

This is actually not new behavior, I tested D6 and it works the same way. What is new is that the rendering system seems to invoke template_preprocess_page much earlier in the rendering process, which means that if you are calling e.g. dpm() in a template file the output gets deferred to a subsequent request. If this is a 404 you'll never see the message.

Of course our live sites never have 404's :-) but it's quite common on a dev site.

I'm not sure what the best solution is - it seems ideally drupal_get_messages would get called late like D6, but if this isn't possible we should consider suppressing messages on 404.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

grendzy’s picture

Status: Active » Needs review
FileSize
749 bytes
Caligan’s picture

Duplicate patch in updated git format (prior is -p0).

Status: Needs review » Needs work

The last submitted patch, 0001-Suppress-status-messages-on-404-pages-2.patch, failed testing.

Caligan’s picture

Status: Needs work » Needs review
FileSize
455 bytes
Caligan’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
FileSize
455 bytes

Same patch rolled for D8.

BrockBoland’s picture

BrockBoland’s picture

FileSize
484 bytes

Re-rolled for new core file structure, but still waiting on steps to reproduce this issue. This will also need a test case.

jemond’s picture

FileSize
708 bytes

Attached is a simple module to reproduce this issue.

Steps to reproduce:

  1. Install Drupal 7 clean
  2. Enable the PHP filter (yay!)
  3. Create a new node with the content below and set the input filter to PHP:
    Hello world!
    <img src="no-image.html" />
    <?php
    print time();
    ?>
    
  4. Install and enable the attached module
  5. View the node

Expected to see: The server time from the previous request in in the Drupal messages area

What I saw: No message

jemond’s picture

BrockBoland’s picture

jemond's demo module will need to be rolled into a test case, but I can't find where drupal_set_message() actually gets tested. Maybe it's not?

jemond’s picture

Status: Needs review » Needs work

The patch in #7 does not appear to fix the issue in Drupal 8. I need to look further into this.

danquah’s picture

Status: Needs work » Needs review
FileSize
5.06 KB

This patch should fix the problem in Drupal 8. The logic has changed somewhat in D8 so the patch in #7 did not apply. The patch includes a testcase that uses the module suggested in #8 to emit test-messages which is then tested for in the testcase.

The testcase is placed under system as messages did not seem to have a testcase. It might be an idea to do a new issue for creating test-cases for messages.

YesCT’s picture

Status: Needs review » Needs work

just a quick standards review.

+++ b/core/modules/system/lib/Drupal/system/Tests/System/PageNotFoundMessagesTest.phpundefined
@@ -0,0 +1,72 @@
+ * Definition of Drupal\system\Tests\System\PageNotFoundTest.

standards have changed a little. Now it's
Contains \Drupal\...

+++ b/core/modules/system/lib/Drupal/system/Tests/System/PageNotFoundMessagesTest.phpundefined
@@ -0,0 +1,72 @@
+  /**
+   * Implement getInfo().
+   */
+  public static function getInfo() {
...
+  /**
+   * Implement setUp().
+   */
+  function setUp() {

no doc block needed on getInfo http://drupal.org/node/325974

or setUp.

Also, setUp should be public.

+++ b/core/modules/system/lib/Drupal/system/Tests/System/PageNotFoundMessagesTest.phpundefined
@@ -0,0 +1,72 @@
+   * Test that 404 pages does not clear messages.
+   */
+  function testPageNotFound() {

third person verb like:
Tests that

+++ b/core/modules/system/lib/Drupal/system/Tests/System/PageNotFoundMessagesTest.phpundefined
@@ -0,0 +1,72 @@
+    // Access a page that will emit a test message (via the page_not_found_message_test module).
+    // The message is set in a preprocess_node hook and wont make it in this page render.

all comments need to wrap at 80 chars. http://drupal.org/node/1354

kim.pepper’s picture

Status: Needs work » Needs review
FileSize
4.19 KB
2.72 KB

Re-rolled against head and applied code style fixes as per #13

sun’s picture

kim.pepper’s picture

Status: Needs review » Needs work

The last submitted patch, 14: suppress-404-messages-885896-14.patch, failed testing.

kim.pepper’s picture

Issue tags: +Needs reroll
kim.pepper’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
4.24 KB

Re-roll.

Status: Needs review » Needs work

The last submitted patch, 19: 885896-suppress-404-messages-19.patch, failed testing.

Status: Needs work » Needs review
joelpittet’s picture

Re-rolled. Tests are the same but the 4xx controller moved. Added to each method

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wturrell’s picture

NB: first day using SimpleTest. Please tell me where I've screwed up.

I'm unclear if this issue / the previous tests are still current.
I've updated them for D8 anyway.

Was confused by the first one - I tried it manually and the session message is displayed immediately, despite "message is set in a preprocess_node hook and wont make it in this page render". Then I thought, well that's just because I'm doing it through the web UI and I'm redirected, and it won't happen when the test runs, but it appears to:

Fail      Other      PageNotFoundMessa   60 Drupal\system\Tests\System\PageNotF
    Did not find messages on page
Pass      Other      PageNotFoundMessa   65 Drupal\system\Tests\System\PageNotF
    No messages on 404 page
Fail      Other      PageNotFoundMessa   71 Drupal\system\Tests\System\PageNotF
    Found messages on page

(clearly if the message is shown in the first of these three, it's no surprise the last test fails too.)

Patch changes:
- move test to /core/modules/system/src/Tests/System
- add the @group annotation
- randomName(10) becomes randomString(10)
- $node->did becomes $node->id()
- phpcs fixes
- update test module info file to YAML for D8

Status: Needs review » Needs work

The last submitted patch, 26: 404_pages_swallow-885896-26.patch, failed testing.

joelpittet’s picture

@wturrell sorry for the late response.

We try to avoid doing phpcs fixes because they muddy the patch for reviewers to tell which changes are pertinent to the fix and which ones are just cleanup. Most clean-up gets posted in a separate or follow-up issue.

Test results are showing that maybe it's still getting swollowed?

joelpittet’s picture

joelpittet’s picture

Sorry, my phpcbf didn't run and didn't tell me.

joelpittet’s picture

The last submitted patch, 29: 404_pages_swallow-885896-26-reroll.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 30: 404_pages_swallow-885896-26-reroll.patch, failed testing.

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
4.39 KB
1.27 KB

Straight reroll to remove coding standard issues related to this patch & also added interdiff.

Status: Needs review » Needs work

The last submitted patch, 34: 404_pages_swallow-885896-34.patch, failed testing.

joelpittet’s picture

Thank you for rerolling:) Yeah the tests seem to show stuff is still not quite right with the patch.

wturrell’s picture

@joelpittet thanks.

See my comments in #26 - I'm aware the test is failing, could do with another pair of eyes on the code / clarity on what the correct sequence should be.

(I realise you only rerolled the previous patch…)

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

We shouldn't need to be logged in for this test?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.