Project

General

Profile

Actions

Bug #95978

open

DataHandler does not catch errors in database query

Added by Jan Delius about 3 years ago. Updated almost 3 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
DataHandler aka TCEmain
Target version:
-
Start date:
2021-11-15
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
7.4
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

In the DataHandler, an attempt is made to catch a DBALException when inserting or updating an existing entry. This class is deprecated, the code itself states that you should use \Exception. If I replace the catch block in the PHP code, the errors are caught again when executing the database query and the DataHandler notices that there was an error.

Example error that should be catched:

[Doctrine\DBAL\Driver\Mysqli\Exception\StatementError]                       
  Incorrect integer value: '' for column `typo3`.`tx_myext_domain_model_mymodel`.`number` at row 1

Actions #1

Updated by Oliver Hader about 3 years ago

By briefly looking into the code, we might use \Doctrine\DBAL\Driver\AbstractException instead...
However, since you have been working on code already, can you please share your current result - either on review.typo3.org or by simply adding a patch-file to this ticket? Thanks in advance!

Actions #2

Updated by Jan Delius about 3 years ago

Oliver Hader wrote in #note-1:

By briefly looking into the code, we might use \Doctrine\DBAL\Driver\AbstractException instead...
However, since you have been working on code already, can you please share your current result - either on review.typo3.org or by simply adding a patch-file to this ticket? Thanks in advance!

Unfortunately, I don't have a clean system at the moment in which I could create or push a patch. However, the class \Doctrine\DBAL\Driver\AbstractException is marked as internal. As far as I understand the comments in the code correctly, one should use the interface Doctrine\DBAL\Driver\Exception. This will catch the corresponding error message.

I must have specified the wrong class ( \Exception ) in the original ticket.

Actions #3

Updated by Jan Delius almost 3 years ago

After closer investigation I came to the following conclusion: The "error" only occurs when "doctrine/dbal" is used in version 2.13.x. In 3.3.x (which is used in the branch main) a Doctrine\DBAL\Driver\Exception is converted to a Doctrine\DBAL\Exception\DriverException inside Doctrine\DBAL\Connection. This "new" class extends the old exception and implements the Driver\Exception interface.

As it seems, we need to catch both types of exception in the core. In the main branch everything can stay as it is.

2.13.x:
- https://github.com/doctrine/dbal/blob/5a175c9a3bd1e0f9fdfd25dfbbb509a712232f12/lib/Doctrine/DBAL/Connection.php#L1537
- https://github.com/doctrine/dbal/blob/5a175c9a3bd1e0f9fdfd25dfbbb509a712232f12/lib/Doctrine/DBAL/DBALException.php#L177

3.3.x:
- https://github.com/doctrine/dbal/blob/484af342655f338dc0d279bfd112496d473fe3ec/src/Connection.php#L1163
- https://github.com/doctrine/dbal/blob/484af342655f338dc0d279bfd112496d473fe3ec/src/Connection.php#L1807
- https://github.com/doctrine/dbal/blob/484af342655f338dc0d279bfd112496d473fe3ec/src/Exception/DriverException.php#L16

Actions

Also available in: Atom PDF