Skip to content

New #868: Add SerializationFailureException - #1196

Merged
vjik merged 9 commits into
yiisoft:masterfrom
KalimeroMK:add-868-serialization-failure-exception
Sep 7, 2026
Merged

New #868: Add SerializationFailureException#1196
vjik merged 9 commits into
yiisoft:masterfrom
KalimeroMK:add-868-serialization-failure-exception

Conversation

@KalimeroMK

Copy link
Copy Markdown
Contributor

Fix #868

Adds SerializationFailureException for 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 in ConvertException, next to the existing IntegrityException mapping.

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (f0b0d2b) to head (bbeb4c0).
⚠️ Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KalimeroMK KalimeroMK closed this Aug 20, 2026
@KalimeroMK KalimeroMK reopened this Aug 20, 2026
@vjik
vjik requested a balanced review from Copilot August 24, 2026 12:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a database exception for SQLSTATE 40001 serialization failures.

Changes:

  • Adds SerializationFailureException.
  • Maps SQLSTATE 40001 centrally 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.

Comment thread src/Exception/ConvertException.php Outdated
Comment thread src/Exception/ConvertException.php Outdated
Comment thread src/Exception/ConvertException.php Outdated
Comment thread src/Exception/ConvertException.php Outdated

if (
($errorInfo[0] ?? null) === '40001'
|| str_contains($this->e->getMessage(), self::MSG_SERIALIZATION_FAILURE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there cases when ($errorInfo[0] ?? null) === '40001' is not enough?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Comment thread src/Connection/AbstractConnection.php Outdated
Comment thread rector.php Outdated
- `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.
Comment thread src/Driver/Pdo/PdoServerInfo.php Outdated
Comment thread tests/Db/Driver/Pdo/PdoCommandTest.php Outdated
- `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.
@Tigrov
Tigrov requested a review from vjik September 5, 2026 07:42
@vjik
vjik merged commit 11032c2 into yiisoft:master Sep 7, 2026
82 checks passed
KalimeroMK pushed a commit to KalimeroMK/KalimeroMK that referenced this pull request Sep 7, 2026
KalimeroMK pushed a commit to KalimeroMK/KalimeroMK that referenced this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SerializationFailureException

5 participants