Download & Extend

DB Log is missing watchdog table after enabling - Need to catch and ignore exceptions thrown in dblog_watchdog()

Project:Drupal core
Version:8.x-dev
Component:dblog.module
Category:bug report
Priority:major
Assigned:Fabianx
Status:needs work
Issue tags:needs backport to D7, Needs tests

Issue Summary

Problem/Motivation

It's completely unacceptable to break a page if we fail to log a message. In particular, this cause painful to debug errors during the installation process, as recently reported in #429188: Watchdog table not installed when watchdog module enabled..

Proposed resolution

Catch and ignore all exceptions thrown in dblog_watchdog().

Remaining tasks

  • Write a patch.
  • Implement a generic test that tries to watchdog() in a Unit Test Case (that doesn't have access to the database).

User interface changes

None.

API changes

None.

Comments

#1

Title:Catch and ignore exceptions thrown in dblog_watchdog()» DB Log is missing watchdog table after enabling - Need to catch and ignore exceptions thrown in dblog_watchdog()
Priority:normal» major

Changing issue title and bumping priority, because:

a) This happens on D7 and D8 with MySQL.
b) The module is enabled, but watchdog table does not exist, such leading to more errors.

Reproducing steps:

* Have any module that adds a message to watchdog on every page load (in this case .../modules/contrib/date/date_context/date_context_date_condition.class.php)
* Enable watchdog either during installation or afterwards.
* Watchdog _is_ enabled, but the watchdog table is missing and leads to more errors on every page load.

IMHO this is at least major, if not critical.

#2

Adding tags

#3

actually it should be the caller of hook_watchdog who eats up the exceptions not each module.

#4

Lets see what testbot says to this patch / test.

( Patch does not include feedback from #3 due to x-post)

AttachmentSizeStatusTest resultOperations
core-Fix-problem-with-watchdog-exceptions-1784548-3.diff3.52 KBIdleFAILED: [[SimpleTest]]: [MySQL] 46,229 pass(es), 1 fail(s), and 0 exception(s).View details | Re-test

#5

Status:active» needs review

#6

Status:needs review» needs work

The last submitted patch, core-Fix-problem-with-watchdog-exceptions-1784548-3.diff, failed testing.

#7

AttachmentSizeStatusTest resultOperations
core-Fix-problem-with-watchdog-exceptions-1784548-7.diff4.22 KBIdleFAILED: [[SimpleTest]]: [MySQL] 46,221 pass(es), 1 fail(s), and 3 exception(s).View details | Re-test

#8

Status:needs work» needs review

#9

Status:needs review» needs work

The last submitted patch, core-Fix-problem-with-watchdog-exceptions-1784548-7.diff, failed testing.

#10

Please add a @throws directive to the docblock for dblog_watchdog() when this patch is next re-rolled.

#11

Assigned to:Anonymous» Fabianx

#12

Status:needs work» needs review

Re-roll that fixes the path to install.inc and adds a docblock to the test method.

@Lars Toomre: The purpose of this patch is to *prevent* that an exception is thrown, not throw one, so it's not necessary to do that. We'd actually have to remove it if there would be one.

@chx: I think it's the responsibility of each module to handle this. Doing it in watchdog() would require is to try/catch each call separately so that each hook is invoked, even if one fails.

AttachmentSizeStatusTest resultOperations
dblog-catch-exception-1784548-12.patch3.69 KBIdleFAILED: [[SimpleTest]]: [MySQL] 46,264 pass(es), 1 fail(s), and 1 exception(s).View details | Re-test

#13

Status:needs review» needs work

The last submitted patch, dblog-catch-exception-1784548-12.patch, failed testing.

#14

Hm. I don't really get why we need that second part of the test? It's complicated due to static caches and not what this patch is about?

Here's a version without that part...

AttachmentSizeStatusTest resultOperations
dblog-catch-exception-1784548-14.patch3.12 KBIdleFAILED: [[SimpleTest]]: [MySQL] 46,242 pass(es), 1 fail(s), and 0 exception(s).View details | Re-test

#15

Status:needs work» needs review

#16

Status:needs review» needs work

The last submitted patch, dblog-catch-exception-1784548-14.patch, failed testing.

#17

I have a second patch, which might be better (based on chx feedback), but which needs work.

Just posting as I had worked on it already. Thanks @berdir:

Please note is a multi patch due to time constraints ...

AttachmentSizeStatusTest resultOperations
core-Fix-problem-with-watchdog-exceptions-1784548-17.diff6.71 KBIdleFAILED: [[SimpleTest]]: [MySQL] 46,249 pass(es), 1 fail(s), and 3 exception(s).View details | Re-test

#18

Status:needs work» needs review

#19

Status:needs review» needs work

The last submitted patch, core-Fix-problem-with-watchdog-exceptions-1784548-17.diff, failed testing.

#20

Status:needs work» needs review

#14: dblog-catch-exception-1784548-14.patch queued for re-testing.

#21

Status:needs review» needs work

#22

What about trying to create the table inside the catch? Eventually watchdog should be a class, and that class should be responsible for installing its own schema, similar to #1167144: Change notice: Make cache backends responsible for their own storage (note my opinion isn't necessarily that popular in that issue either).

#23

I want to add an observation that appears to be related to this issue.

When these symptoms are present drush pml shows dblog as not installed but admin/modules shows it as installed. A drush en dblog -y also states that dblog is already installed.

Update:
Drupal 7.21
Drush 5.1

I also stated above initially that drush en dblog -y states dblog is not installed, I meant to say it states it is already installed and have corrected it above.

#24

Btw, I would support this as critical too. I cannot flush cache on a site affected by this right now. See screenshot.

AttachmentSizeStatusTest resultOperations
screenshot_20130403-09:44:40.png106.92 KBIgnored: Check issue status.NoneNone

#25

Drush reports as 'not installed' because it checks that the schema version whereas the GUI checks the status.