Skip to content

[13.x] Only handle unique constraint violations when acquiring database locks#60269

Closed
Tresor-Kasenda wants to merge 1 commit into
laravel:13.xfrom
Tresor-Kasenda:fix-database-lock-query-exceptions
Closed

[13.x] Only handle unique constraint violations when acquiring database locks#60269
Tresor-Kasenda wants to merge 1 commit into
laravel:13.xfrom
Tresor-Kasenda:fix-database-lock-query-exceptions

Conversation

@Tresor-Kasenda
Copy link
Copy Markdown
Contributor

Description

This pull request updates DatabaseLock::acquire() so it only falls back to updating an existing lock when the insert fails due to a unique constraint violation.

Previously, the method caught any QueryException, which could hide unrelated database errors such as missing tables, invalid SQL, permission issues, or connection problems. Those errors should be surfaced to the developer instead of being treated as a lock contention case.

This PR also adds regression coverage for both paths:

  • non-unique insert query exceptions are rethrown
  • unique constraint violations still fall back to updating the existing lock

Fixes #60171.

…se locks

## Description

This pull request updates `DatabaseLock::acquire()` so it only falls back to updating an existing lock when the insert fails due to a unique constraint violation.

Previously, the method caught any `QueryException`, which could hide unrelated database errors such as missing tables, invalid SQL, permission issues, or connection problems. Those errors should be surfaced to the developer instead of being treated as a lock contention case.

This PR also adds regression coverage for both paths:

- non-unique insert query exceptions are rethrown
- unique constraint violations still fall back to updating the existing lock

Fixes laravel#60171.

## Tests

```bash
php vendor/bin/phpunit tests/Integration/Database/DatabaseLockTest.php
vendor/bin/pint --dirty --format=agent
git diff --check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants