Skip to content

Commit

Permalink
bug #54305 [Cache][Lock] Identify missing table in pgsql correctly an…
Browse files Browse the repository at this point in the history
…d address failing integration tests (arifszn)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Cache][Lock] Identify missing table in pgsql correctly and address failing integration tests

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        |
| License       | MIT

## Description

The existing code snippet is as follows:
```php
$code = $exception->errorInfo ? $exception->errorInfo[1] : $exception->getCode();

switch (true) {
    case 'pgsql' === $driver && '42P01' === $code:
```

When we print `$exception->errorInfo[1]`, it yields 7, which is interpreted as false. This behavior has been rectified.

![image](https://github.com/symfony/symfony/assets/45073703/3f928fcb-ba1c-4113-a0d9-b4d04a19bc70)

**Additionally, this pull request fixes the integration tests that have been failing persistently until now.**

![image](https://github.com/symfony/symfony/assets/45073703/050fe625-4ff6-423d-9c89-ed183f36e670)

Commits
-------

98fe71a [Cache][Lock] Identify missing table in pgsql correctly and address failing integration tests
  • Loading branch information
nicolas-grekas committed Mar 16, 2024
2 parents cb3ec06 + 98fe71a commit 07a6ffe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ private function getServerVersion(): string
private function isTableMissing(\PDOException $exception): bool
{
$driver = $this->driver;
$code = $exception->errorInfo ? $exception->errorInfo[1] : $exception->getCode();
[$sqlState, $code] = $exception->errorInfo ?? [null, $exception->getCode()];

switch (true) {
case 'pgsql' === $driver && '42P01' === $code:
case 'pgsql' === $driver && '42P01' === $sqlState:
case 'sqlite' === $driver && str_contains($exception->getMessage(), 'no such table:'):
case 'oci' === $driver && 942 === $code:
case 'sqlsrv' === $driver && 208 === $code:
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Lock/Store/PdoStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ private function getCurrentTimestampStatement(): string
private function isTableMissing(\PDOException $exception): bool
{
$driver = $this->getDriver();
$code = $exception->errorInfo ? $exception->errorInfo[1] : $exception->getCode();
[$sqlState, $code] = $exception->errorInfo ?? [null, $exception->getCode()];

switch (true) {
case 'pgsql' === $driver && '42P01' === $code:
case 'pgsql' === $driver && '42P01' === $sqlState:
case 'sqlite' === $driver && str_contains($exception->getMessage(), 'no such table:'):
case 'oci' === $driver && 942 === $code:
case 'sqlsrv' === $driver && 208 === $code:
Expand Down

0 comments on commit 07a6ffe

Please sign in to comment.