Repeatable: Always
Steps to repeat:

  1. Set up a fresh install of Drupal 8.
  2. Drop the site database.
  3. Visit the site in your browser.

Expected results:
An error explaining the root cause of the situation (Error in accessing the Drupal database 'databasename'. or similar).

Actual results:
The following error is thrown:
Fatal error: Call to a member function get() on a non-object in /var/www/slukdrupal8/core/includes/theme.maintenance.inc on line 59

Tested with commit c962f4f5bc814cdf61c0e4de315295e899379c28, 8.x head at 2013-02-05 10:30 UTC.

Comments

tkitchin’s picture

Event summary:

  • DrupalKernel tries to access the DB cache for the first time as part of the load() call at DrupalKernel:302. This throws a PDOException since there's no DB.
  • _drupal_exception_handler() takes over, and bootstraps Drupal with the maintenance theme in order to display the error.
  • The bootstrapping in /core/includes/theme.maintenance.inc doesn't set up the drupal_container(), so when the container is accessed in theme.maintenance.inc it throws the exception given in the issue description.
  • An exception during exception handling just drops it to normal PHP error handling, since otherwise we risk a loop.

In short, the original error during DrupalKernel initialisation is concealed by an error during the maintenance mode setup (although it only happens if we got there via an exception rather than, say, running the installer). I'm working on resolving this by bootstrapping the drupal_container as part of the maintenance theme bootstrapping.

tkitchin’s picture

Patch to implement a MaintenanceContainerBuilder which can also be used in the installer bootstrap (see todo at: http://drupalcode.org/project/drupal.git/blob/HEAD:/core/includes/instal...), and uses it there and in the maintenance mode bootstrap when a pre-kernel-boot exception sends us there. Also sets the pre-kernel-boot exception handler to render the Response object if it generates one, as previously it wasn't actually using it for anything thus causing a WSOD in any exception handled by it.

tkitchin’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, drupal-bootstrap-container-in-maintenance-mode-1908310-2.patch, failed testing.

stevesmename’s picture

Status: Needs work » Needs review

Same error happened for me (same commit), I had instead setup a settings.php config file (copied from default.settings.php), I entered in my new database details and as the original post I had my database emptied. I expected Drupal to install similar to D7 but received same error described in original post.

tkitchin’s picture

Test failures from the previous patch were due to the patch replacing an existing container if one existed. This patch checks that there isn't already a container before bootstrapping a minimal one.

tkitchin’s picture

Added some documentation. Also slight rename to better fit naming guidelines.

tkitchin’s picture

Fixed some minor code style issues.

damienmckenna’s picture

damienmckenna’s picture

The error still happens after applying the patch.

damienmckenna’s picture

Status: Needs review » Needs work

With the scenario described in the main issue the following error is displayed on the homepage after the database is purged:

Fatal error: Class 'Drupal\rest\EventSubscriber\RouteSubscriber' not found in core/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php on line 142

I started the installer (install.php), was able to select the language and profile, it verified the requirements, found the old settings.php file with the database configuration files, as it was running the "installation profile" step of the installer it fails with the error described in the issue summary:

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: http://d8.dev/core/install.php?langcode=en&profile=standard&id=1&op=do_nojs&op=do StatusText: OK ResponseText: Fatal error: Call to a member function get() on a non-object in core/modules/views/lib/Drupal/views/ViewStorageController.php on line 26

sun’s picture

Please note that this issue does not talk about install.php.

This issue is about visiting the actual site (index.php) after dropping the database.

Therefore, all of the changes to install.inc should be reverted and removed from this patch.

Due to that, #11 sounds unrelated too, but I'm not 100% clear on that.

tkitchin’s picture

Thanks for the comments. This patch is the same minus the changes to install.core.inc - I was mostly fixing it in passing since the install.core.inc code has a @todo suggesting pulling the code out, and the requirements for the container at that point are essentially identical as far as I can see. You're right, though - not actually related to the issue, so shouldn't happen here. Apologies for the scope creep, there.

Re: #11, I haven't been able to reproduce that, I'm afraid. I'm testing with a fresh d8 deployment, no additional modules activated or configuration changed.

tkitchin’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, drupal-maintenance-bootstrap-1908310-13.patch, failed testing.

damienmckenna’s picture

@sun: Would you recommend merging problems during the installation process into #1895100: Remove pre-existing compiled PHP code when re-installing Drupal core or adding a new issue?

tkitchin’s picture

Status: Needs work » Needs review
damienmckenna’s picture

StatusFileSize
new1.97 KB

The patch from #13 rerolled, and I fixed some whitespace errors that git-apply reported.

damienmckenna’s picture

StatusFileSize
new4.27 KB

Ack, the last patch missed MaintenanceContainerBuilder.php.

damienmckenna’s picture

Status: Needs review » Needs work

The patch in #19 does not always do what is described.

These scenarios all have the patch from #19 applied.

Scenario #1: Tables removed.

  • Start off with nothing in sites/default and an empty database.
  • Install D8 with the standard profile.
  • After the site has finished installing, remove all tables from the database so that the db values in settings.php are still correct.
  • Load the homepage, the following fatal error is returned:
    Call to a member function get() on a non-object in core/includes/config.inc on line 105

Scenario #2: Database removed.

  • Start off with nothing in sites/default and an empty database.
  • Install D8 with the standard profile.
  • After the site has finished installing, remove the entire database so that the db values in settings.php are no longer correct.
  • Load the homepage, the following fatal error is returned:
    Call to a member function get() on a non-object in core/includes/config.inc on line 105

Scenario #3: Tables removed and compiled PHP files removed.

  • Start off with nothing in sites/default and an empty database.
  • Install D8 with the standard profile.
  • After the site has finished installing, remove all tables from the database so that the db values in settings.php are still correct and remove everything from sites/default/files.
  • Load the homepage, the following error is returned:
    The website really has encountered an error. Please try again later.
damienmckenna’s picture

I split up the config() function from \Drupal\Core\Config\Config to the following:

function config($name) {
  $container = drupal_container();
  $factory = $container->get('config.factory');
  $config = $factory->get($name);
  return $config;
}

The error then pointed to the second line, meaning that the value returned from drupal_container() is invalid.

damienmckenna’s picture

The documentation for drupal_container() says:

Retrieves the Drupal Container to standardize object construction.

@deprecated This function has been replaced by the \Drupal class. Use that instead.

So, does this class need to be updated to a new structure before anything else should proceed?

damienmckenna’s picture

Issue tags: +SprintWeekend2013

Tag.

damienmckenna’s picture

alexpott’s picture

Priority: Normal » Critical
Status: Needs work » Needs review
StatusFileSize
new118.42 KB
new106.57 KB
new6.51 KB

This patch changes the direction slightly and move responsibility to the error handling system to ensure it has enough of a container to function properly.

Without this patch
nodb_bad_error.png

With this patch
maintenancetheme_db_message-2.png

I believe this is release blocking as the current message when the db is not available is very very obscure.

swentel’s picture

Interesting - shouldn't we then also remove that line in index.php ? That one is just completely not informative :)

rivimey’s picture

Issue summary: View changes
StatusFileSize
new88.59 KB

In reviewing this issue I am using D8 from git as of 21:35 on 11-Dec, #51560a3a0424

First, without applying a patch:
-Creating a default site and then dropping the tables in the database using drush sql-drop results in the following message on an otherwise white browser screen:

If you have just changed code (for example deployed a new module or moved an existing one) read http://drupal.org/documentation/rebuild

- Creating a default site and then dropping the database completely results in the same message.

I applied the patch from #25, which succeeds with an offset of 10 lines to one of the two files, and recreated the site.

Dropping the tables as before now returns a similar screen to that shown in #25, but it's not the same. In particular, the Drupal logo and 'please try again' messages are missing. However the central error is present and moderately clear. A screenshot is attached.

Probably RTBC but curious about the logo so not changing status.

rivimey’s picture

StatusFileSize
new6.5 KB

Rerolled the patch from #25, git diff, otherwise unchanged.

steinmb’s picture

StatusFileSize
new65.77 KB
new57.7 KB
new9.77 KB
new60.15 KB

PHP 5.5.5
MariaDB 5.5.32
Drupal 8.x HEAD

Database stopped

before

No db present

after #28

Path 28 installed, db. stopped

All tables dropped

before

No tables

after #28

No tables patch 28

steinmb’s picture

Status: Needs review » Needs work

Ref. #29. No end users get this.

sun’s picture

I fixed the error and exception handling in the installer very recently. In case of an error, you should see a verbose backtrace now.

Can you test again with latest 8.x/HEAD, please?

sun’s picture

Note that the patch in #2194111: Error handler throws exception when service container is not (fully) available yet fixes the last remaining "errors caused by errors" problems. Once that has landed, we should be able to properly debug what's going here.

catch’s picture

Status: Needs work » Closed (duplicate)

Now fixed. We could do without the literally printed html tags in the exception message, but that's minor.

Exception: <ul><li>To start over, you must empty your existing database, delete your active configuration, and copy <em>default.settings.php</em> over <em>settings.php</em>.</li><li>To install to a different database, edit the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li><li>To locate your active configuration, view the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li><li>To upgrade an existing installation, proceed to the <a href="http://8.x.localhost/core/update.php">update script</a>.</li><li>View your <a href="http://8.x.localhost">existing site</a>.</li></ul> in install_begin_request() (line 526 of core/includes/install.core.inc).
install_begin_request(Array)
install_drupal()
sun’s picture

naim’s picture

this is still an issue in drupal-8.0.0-beta12
How should I wipe and reinstall drupal to avoid this?