Problem/Motivation

#3137883: Deprecate passing a StatementInterface object to Connection::query added a DatabaseExceptionWrapper. The third argument should be the \Throwable and not the code.

throw new DatabaseExceptionWrapper($message, 0, $e->getCode());

Steps to reproduce

  • Write some code that does a bad insert. The expected exception is not a DatabaseExceptionWrapper.

Proposed resolution

Change to throw new DatabaseExceptionWrapper($message, $e->getCode(), $e);

Remaining tasks

1. Write a test in the database group to assert that bad queries have the correct exception thrown. To start with, let's focus on queries that get caught in DatabaseExceptionWrapper exceptions and not in the other exceptions. This could have a data provider to assert a query on a specific database driver.
2. Make the fix.
3. Review

User interface changes

No

API changes

No

Data model changes

No

Release notes snippet

CommentFileSizeAuthor
#9 3210071-TEST-ONLY-FAIL.patch1.9 KBadam-vessey

Issue fork drupal-3210071

Command icon 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

mradcliffe created an issue. See original summary.

daffie’s picture

Issue tags: -Novice

@mradcliffe: Good find! Only I do not think that a novice can easily fix this as we also need add a test for this fix.

mradcliffe’s picture

Issue summary: View changes
Issue tags: +Needs tests

I guess writing a test first would be ideal, and that might not be as straightforward. But after that there's no reason a new contributor couldn't provide a review or the fix itself if they wanted to collaborate.

I'll clarify the steps in the issue summary, thank you.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pahles’s picture

Is there any progress on this issue? I'm running into this error multiple times each day now. Is the proposed solution valid? Can I 'just' (until a real solution exists) patch the file?

mradcliffe’s picture

Is there any progress on this issue? I'm running into this error multiple times each day now. Is the proposed solution valid? Can I 'just' (until a real solution exists) patch the file?

There hasn't been any progress on this issue, but if you're up for it, you can create a patch using a git checkout of drupal core, and then upload it so you can use it on your site AND make progress on the issue at the same time.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

adam-vessey’s picture

StatusFileSize
new1.9 KB

Slapped together something of a test; though, not 100% happy with the amount of mocking necessary (without into actually using the DB, that is)... half-tempted to suggest pulling the exception mapping/wrapping out into a separate method that could be more simply targeted for testing this specific issue, but may be excessive.

adam-vessey’s picture

Hmm, had older stuff locally that I was looking at, not realizing that things have been pulled out to separate modules. This... might no longer be an issues, as of https://www.drupal.org/node/3129492 #3185269: Introduce Connection::lastInsertId and deprecate the 'return' query option and Database::RETURN_* constants (https://www.drupal.org/node/3129492 just moved things around, from Drupal core out to modules)?

... Indeed seems to be the case, with the wrapping now out in the "ExceptionHandler" (https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/lib/Drupal/C...), being invoked from the "pgsql" module's "Insert" (https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/modules/pgsq...), assuming there's not another "ExceptionHandler" being introduced somewhere which exhibits this issue?

paul121’s picture

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

daffie’s picture