New #868: Add SerializationFailureException - #1196
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1196 +/- ##
============================================
- Coverage 98.62% 98.62% -0.01%
+ Complexity 1645 1641 -4
============================================
Files 120 120
Lines 4288 4283 -5
============================================
- Hits 4229 4224 -5
Misses 59 59 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a database exception for SQLSTATE 40001 serialization failures.
Changes:
- Adds
SerializationFailureException. - Maps SQLSTATE
40001centrally and adds a test. - Updates the changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Exception/SerializationFailureException.php |
Defines the new exception type. |
src/Exception/ConvertException.php |
Converts matching failures to the new type. |
tests/Db/Exception/ConvertExceptionTest.php |
Tests serialization-failure conversion. |
CHANGELOG.md |
Documents the feature. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| if ( | ||
| ($errorInfo[0] ?? null) === '40001' | ||
| || str_contains($this->e->getMessage(), self::MSG_SERIALIZATION_FAILURE) |
There was a problem hiding this comment.
Are there cases when ($errorInfo[0] ?? null) === '40001' is not enough?
There was a problem hiding this comment.
in real usage PDO always populates errorInfo, so the message fallback only served manually constructed exceptions I Removed it so the check now relies solely on $errorInfo[0] and the test sets errorInfo the way PDO would.
The rector job failed because Rector still had 5 pending IfToNullCoalescingAssignRector fixes on master. The workflow then tried to auto-commit them and died on `git fetch origin <head-ref>`, since for a fork PR `origin` is yiisoft/db and the branch does not exist there. Applying the fixes leaves the auto-commit step with nothing to stage, so it exits cleanly. PdoServerInfo::getVersion() is skipped instead of rewritten: `??=` drops the `/** @var string */` hint that Psalm needs, and Psalm does not read the annotation above a `??=` assignment, so the rewrite produced 3 Psalm errors.
- `AbstractConnection::beginTransaction()`: merge the two assignments into a single `$this->getTransaction() ?? $this->createTransaction()`. - `PdoServerInfo::getVersion()`: convert to `??=` instead of skipping `IfToNullCoalescingAssignRector`. The version lookup moves to a helper that narrows the PDO attribute with `is_string()`, which also removes the `/** @var string */` assertion.
Cover the three lines Codecov reported as missing from the patch: - `AbstractConnection::beginTransaction()` — a new transaction is created when none is active, and an active one is reused on a nested call. - `AbstractPdoCommand::bindParam()` — the data type is resolved from the value when not given explicitly. - `AbstractPdoCommand::bindValue()` — same, asserted per resolved type. These paths were previously exercised only by `tests/Common/*`, which runs in the driver repositories and not in the `Db` suite that feeds Codecov.
- `PdoServerInfo::getVersion()`: apply the suggested one-line form. Psalm types `PDO::getAttribute()` as possibly returning an array, so the cast needs a targeted suppression. - Remove the tests added for the lines Codecov reported as missing. Those lines are already covered for every supported DBMS by `CommonPdoCommandTest` and `CommonPdoConnectionTest`; only the "Db", "ActiveRecord" and "DbMigration" suites upload coverage, so the report never sees it.
Fix #868
Adds
SerializationFailureExceptionfor SQLSTATE code 40001 (serialization failure, e.g. transaction deadlock in concurrent updates). The code is the same for all databases, so the conversion is done centrally inConvertException, next to the existingIntegrityExceptionmapping.