Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix DBAL exception handling in setValues #37520

Merged
merged 1 commit into from
Apr 3, 2023

Conversation

blizzz
Copy link
Member

@blizzz blizzz commented Mar 31, 2023

Summary

This seems to be a left over after abstracting DBAL. Nowadays, IQueryBuilder::executeStatement() only throws a \OCP\DB\Exception, where previously original DBAL exceptions where thrown. These are now wrapped, the orignal classes are now mapped to a reason.

(This is a by-catch of testing ldap_contacts_backend and wondering/debugging why its occ edit command was failing).

P.S.: There might be more opportunities for adjustment in this file, did not check further.

Checklist

@blizzz blizzz added bug 3. to review Waiting for reviews labels Mar 31, 2023
@blizzz blizzz added this to the Nextcloud 27 milestone Mar 31, 2023
@blizzz blizzz requested review from nickvergessen, ChristophWurst, a team, ArtificialOwl, icewind1991 and come-nc and removed request for a team March 31, 2023 13:33
@blizzz
Copy link
Member Author

blizzz commented Mar 31, 2023

/backport to stable26

@blizzz
Copy link
Member Author

blizzz commented Mar 31, 2023

25 and below are not affected, since it delegates execution the original Doctrine QueryBuilder and does not catch Exceptions.

@nickvergessen
Copy link
Member

Can we have a test if this is still used :)

@blizzz
Copy link
Member Author

blizzz commented Mar 31, 2023

Can we have a test if this is still used :)

definitely, not ticked in the boxes up there yet

This seems to be a left over after abstracting DBAL. Nowadays,
IQueryBuilder::executeStatement() only throws a \OCP\DB\Exception, where
previously original DBAL exceptions where thrown. These are now wrapped,
the orignal classes are now mapped to a reason.

Signed-off-by: Arthur Schiwon <[email protected]>
@blizzz blizzz force-pushed the fix/noid/fix-dbal-exception-handling branch from d009b5f to 997c2a2 Compare March 31, 2023 15:01
@blizzz
Copy link
Member Author

blizzz commented Mar 31, 2023

Tests added (it's sorta indirect i confess). Without the fix, they would fail with:

PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.13
Configuration: phpunit-autotest.xml

..EE                                                                4 / 4 (100%)

Time: 00:00.020, Memory: 46.88 MB

There were 2 errors:

1) Test\Security\CredentialsManagerTest::testUpdate with data set #0 ('alice', 'privateCredentials')
OC\DB\Exceptions\DbalException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_storages_credentials.user, oc_storages_credentials.identifier

/srv/http/nextcloud/stable26/lib/private/DB/Exceptions/DbalException.php:70
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:328
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:396
/srv/http/nextcloud/stable26/lib/private/DB/ConnectionAdapter.php:114
/srv/http/nextcloud/stable26/lib/private/Security/CredentialsManager.php:72
/srv/http/nextcloud/stable26/tests/lib/Security/CredentialsManagerTest.php:61

Caused by
Doctrine\DBAL\Exception\UniqueConstraintViolationException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_storages_credentials.user, oc_storages_credentials.identifier

/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php:44
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1814
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1749
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1163
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:297
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php:354
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:280
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:326
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:396
/srv/http/nextcloud/stable26/lib/private/DB/ConnectionAdapter.php:114
/srv/http/nextcloud/stable26/lib/private/Security/CredentialsManager.php:72
/srv/http/nextcloud/stable26/tests/lib/Security/CredentialsManagerTest.php:61

Caused by
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_storages_credentials.user, oc_storages_credentials.identifier

/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Driver/PDO/Exception.php:30
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php:103
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1153
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:297
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php:354
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:280
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:326
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:396
/srv/http/nextcloud/stable26/lib/private/DB/ConnectionAdapter.php:114
/srv/http/nextcloud/stable26/lib/private/Security/CredentialsManager.php:72
/srv/http/nextcloud/stable26/tests/lib/Security/CredentialsManagerTest.php:61

Caused by
PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_storages_credentials.user, oc_storages_credentials.identifier

/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php:101
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1153
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:297
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php:354
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:280
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:326
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:396
/srv/http/nextcloud/stable26/lib/private/DB/ConnectionAdapter.php:114
/srv/http/nextcloud/stable26/lib/private/Security/CredentialsManager.php:72
/srv/http/nextcloud/stable26/tests/lib/Security/CredentialsManagerTest.php:61

2) Test\Security\CredentialsManagerTest::testUpdate with data set #1 ('', 'systemCredentials')
OC\DB\Exceptions\DbalException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_storages_credentials.user, oc_storages_credentials.identifier

/srv/http/nextcloud/stable26/lib/private/DB/Exceptions/DbalException.php:70
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:328
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:396
/srv/http/nextcloud/stable26/lib/private/DB/ConnectionAdapter.php:114
/srv/http/nextcloud/stable26/lib/private/Security/CredentialsManager.php:72
/srv/http/nextcloud/stable26/tests/lib/Security/CredentialsManagerTest.php:61

Caused by
Doctrine\DBAL\Exception\UniqueConstraintViolationException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_storages_credentials.user, oc_storages_credentials.identifier

/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php:44
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1814
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1749
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1163
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:297
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php:354
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:280
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:326
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:396
/srv/http/nextcloud/stable26/lib/private/DB/ConnectionAdapter.php:114
/srv/http/nextcloud/stable26/lib/private/Security/CredentialsManager.php:72
/srv/http/nextcloud/stable26/tests/lib/Security/CredentialsManagerTest.php:61

Caused by
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_storages_credentials.user, oc_storages_credentials.identifier

/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Driver/PDO/Exception.php:30
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php:103
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1153
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:297
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php:354
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:280
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:326
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:396
/srv/http/nextcloud/stable26/lib/private/DB/ConnectionAdapter.php:114
/srv/http/nextcloud/stable26/lib/private/Security/CredentialsManager.php:72
/srv/http/nextcloud/stable26/tests/lib/Security/CredentialsManagerTest.php:61

Caused by
PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: oc_storages_credentials.user, oc_storages_credentials.identifier

/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php:101
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Connection.php:1153
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:297
/srv/http/nextcloud/stable26/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php:354
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:280
/srv/http/nextcloud/stable26/lib/private/DB/QueryBuilder/QueryBuilder.php:326
/srv/http/nextcloud/stable26/lib/private/DB/Connection.php:396
/srv/http/nextcloud/stable26/lib/private/DB/ConnectionAdapter.php:114
/srv/http/nextcloud/stable26/lib/private/Security/CredentialsManager.php:72
/srv/http/nextcloud/stable26/tests/lib/Security/CredentialsManagerTest.php:61

ERRORS!
Tests: 4, Assertions: 4, Errors: 2.

@blizzz blizzz merged commit 84c76a8 into master Apr 3, 2023
@blizzz blizzz deleted the fix/noid/fix-dbal-exception-handling branch April 3, 2023 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants