Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Cache][HttpFoundation][Lock] Fix PDO store not creating table + add tests#52459
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| switch (true) { | ||
| case'pgsql' ===$driver &&'42P01' ===$code: | ||
| case'sqlite' ===$driver &&str_contains($exception->getMessage(),'no such table:'): | ||
| case'oci' ===$driver &&942 ===$code: | ||
| case'sqlsrv' ===$driver &&208 ===$code: | ||
| case'mysql' ===$driver &&1146 ===$code: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Taken from Doctrine.
derrabus commentedNov 5, 2023
Can we add a test? |
HypeMC commentedNov 5, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@derrabus Didn't notice postgres was already part of the integration suit, I'll add a test. |
e8d10cb to4c13babCompareUh oh!
There was an error while loading.Please reload this page.
| if ($host =getenv('POSTGRES_HOST')) { | ||
| yield'PostgreSQL' => ['pgsql:host='.$host.';user=postgres;password=password']; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@derrabus This should be ok, without my changes this test fails:
1) Symfony\Component\Lock\Tests\Store\PdoStoreTest::testDsn with data set "PostgreSQL" ('pgsql:host=localhost;user=pos...d=pass')PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "lock_keys" does not existLINE 1: UPDATE lock_keys SET key_expiration = CAST(EXTRACT(epoch FRO...| }catch (\PDOException$e) { | ||
| // the lock is already acquired. It could be us. Let's try to put off. | ||
| $this->putOffExpiration($key,$this->initialTtl); | ||
| if ($this->isTableMissing($e) && (!$conn->inTransaction() ||\in_array($this->driver, ['pgsql','sqlite','sqlsrv'],true))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I just noticed that thePdoAdapter hasthe same logic but without the$this->isTableMissing() part so I'm wondering, should I add it there as well, or remove it form here to keep it consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
yes indeed, also in DoctrineDbalAdapter, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The DBAL adapter catches TableNotFoundException so it is already fine (and the DBAL adapter uses the DBAL API that does the preparation and the execution internally so the try/catch wraps both).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
the try/catch is around the call to prepare, not to execute, that's why I'm wondering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I've added the logic toPdoAdapter, theDoctrineDbalAdapter already works as expected. I've added some tests to the adapters/stores to make super everything works as expected.
0431dc3 to2d0b487Comparenicolas-grekas commentedNov 7, 2023
There are some deprecations, are they related? |
2d0b487 tocc736c3CompareHypeMC commentedNov 7, 2023
@nicolas-grekas Should be good now. |
nicolas-grekas commentedNov 15, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Aren't the remaining deprecations related? https://github.com/symfony/symfony/actions/runs/6788097634/job/18452337658?pr=52459#step:11:1001 |
cc736c3 toccdf227CompareHypeMC commentedNov 15, 2023
@nicolas-grekas Yes, you're right, took me a while to figure this one out. I initially thought that it wasn't related to my changes cause I didn't make any in |
src/Symfony/Component/Cache/Tests/Adapter/DoctrineDbalAdapterTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
ccdf227 to710c1c9CompareUh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Cache/Tests/Adapter/DoctrineDbalAdapterTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
710c1c9 tob6e4869Comparesrc/Symfony/Component/Cache/Tests/Adapter/DoctrineDbalAdapterTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
6a4254d tob75880eCompareUh oh!
There was an error while loading.Please reload this page.
b75880e tocb5d832Comparenicolas-grekas commentedNov 20, 2023
Thank you@HypeMC. |
…eMC)This PR was merged into the 6.4 branch.Discussion----------[Cache][Lock] `PdoAdapter`/`PdoStore` minor cleanup| Q | A| ------------- | ---| Branch? | 6.4| Bug fix? | no| New feature? | no| Deprecations? | no| Issues | -| License | MITFollow up to#52459.Basically some code cleanup such as using `match` instead of `switch` + a minor sync between the `PdoAdapter` and `PdoStore`.I've targeted 6.4 since this is just a minor code cleanup, but I can switch to 7.1 if needed.Commits-------45e17d5 [Cache][Lock] `PdoAdapter`/`PdoStore` minor cleanup
Unlike e.g. SQLite, PostgreSQL doesn't throw an exception on
$conn->prepare()if the table is missing, it instead throws it on$stmt->execute(), so the table never gets created.The table used to get created, but the behavior was broken with#43332.