Follow-up from #3065283: Don't modify maintenance page registry on DB failure which discovered this bug.
Problem/Motivation
The _template_preprocess_default_variables() helper function provides $variables['db_is_active'], but its meaning has changed over time.
When #688294: Switch from db_is_active() to proper exception catching was committed, it used drupal_is_front_page() to determine whether there was an active DB connection and, if an exception was thrown, would set $variables['db_is_active'] to FALSE accordingly.
I suspect that originally, drupal_is_front_page() used to initiate a DB call somewhere along the chain.
This is, however, no longer the case as I suspect that, over time, these subsequent functions were optimized so avoid DB calls.
Thus, this variable really only means "in maintenance mode", not "is the database active".
Proposed resolution
Actually check whether the DB is accessible.
Remaining tasks
TBD
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
TBD
Issue fork drupal-3082948
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
markhalliwellI suppose this (variable name being misleading) is true of HEAD as well:https://git.drupalcode.org/project/drupal/blob/9af697c53bfb03c48b2fb145f...
Seems 8.x simply did away with the try/catch block after entirely, but its value is still just a reference to
!defined('MAINTENANCE_MODE').Comment #12
smustgrave commentedThis came up as the daily BSI target.
This one is tricky as I'm not sure it's a bug as it appears to be by design. The key 'db_is_active' could be confusing so maybe that could be argued but the fact it doesn't call the DB anymore seems to be a decision.
Kinda not sure what should happen here..
Comment #13
longwaveSo
db_is_activeis set in two places:then
I think the second one actually covers the case that the IS talks about? However this is also called without a guard elsewhere, so the try/catch here is likely ineffective on its own as an exception can happen elsewhere.
db_is_activeis in turn used to set an duplicate flag:This is then documented in
html.html.twigand applies adb-offlineclass if the database is offline. There is no CSS for the class, however.I also searched contrib and can find no real usage of any of these:
https://search.tresbien.tech/search?q=db_is_active
https://search.tresbien.tech/search?q=db_offline
https://search.tresbien.tech/search?q=db-offline
This feels somewhat legacy and I think we should consider deprecating it all for removal.
Comment #16
longwaveFull disclosure: trying something new here, using an AI agent to work on issues and tests in a private clone of core. There is always a human in the loop, I manually review and approve all output before pushing back here. Commits and pushes by @longwave-bot are from the agent.
The changes here were written by DeepSeek v4 Flash.
Comment #17
smustgrave commentedMind tweaking the IS seems like we are still just checking maintenance mode, which I'm fine with but can we document that please