Uh oh!
There was an error while loading. Please reload this page.
fix: re-encode updatedAt in increase/decreaseDocumentAttribute with preserveDates - #831
Conversation
…reserveDates is enabled When preserveDates is true, getUpdatedAt() returns the decoded ISO 8601 format (e.g. 2026-03-10T10:33:54.726+00:00) which gets passed directly to the adapter. MariaDB rejects this format. Re-encode to DB format (Y-m-d H:i:s.v) before passing to the adapter.
📝 WalkthroughWalkthroughThis change normalizes existing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/e2e/Adapter/Scopes/DocumentTests.php`:
- Around line 1548-1563: The test enables preserveDates via
Database::setPreserveDates(true) but does not guarantee it is reset if an
assertion or operation fails; wrap the section that fetches the document, calls
increaseDocumentAttribute/decreaseDocumentAttribute, and asserts updatedAt in a
try/finally so that Database::setPreserveDates(false) is always executed in the
finally block, ensuring preserveDates is restored regardless of exceptions or
assertion failures.
- Around line 1550-1561: The test currently only asserts updatedAt didn't change
under preserveDates; also assert the numeric attributes actually changed: after
calling $database->increaseDocumentAttribute('increase_decrease',
$document->getId(), 'increase', 1) fetch the document ($after) and assert its
'increase' value equals the original $before->getAttribute('increase') + 1, and
after calling $database->decreaseDocumentAttribute(..., 'decrease', 1) fetch
again and assert 'decrease' equals original $before->getAttribute('decrease') -
1 (use the existing $before, $after variables and the
increaseDocumentAttribute/decreaseDocumentAttribute calls to locate where to add
these assertions).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7bdcae3f-5a79-4a9b-a218-3f2cb0104392
📒 Files selected for processing (2)
src/Database/Database.phptests/e2e/Adapter/Scopes/DocumentTests.php
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
When
preserveDatesis enabled,increaseDocumentAttributeanddecreaseDocumentAttributepass the decoded ISO 8601$updatedAt(2026-03-10T10:33:54.726+00:00) directly to the SQL adapter, which expects DB format (Y-m-d H:i:s.v). This causesSQLSTATE[22007]: Invalid datetime formaton MariaDB.Other methods like
createDocumentandupdateDocumentdon't have this issue because they go through theencode()pipeline which handles the conversion.Fix
Re-encode
$updatedAtusingDateTime::format()before passing it to the adapter.Test plan
preserveDatesenabled