Skip to content

[6.x] Fix nocache database driver failing on MySQL with invalid UTF-8#14505

Merged
jasonvarga merged 3 commits into6.xfrom
fix-nocache-mysql-utf8
Apr 16, 2026
Merged

[6.x] Fix nocache database driver failing on MySQL with invalid UTF-8#14505
jasonvarga merged 3 commits into6.xfrom
fix-nocache-mysql-utf8

Conversation

@jasonvarga
Copy link
Copy Markdown
Member

Fixes #14504.

Problem

Since 6.10.0, DatabaseSession::cacheRegion() stores serialize($region) directly into the region LONGTEXT column of nocache_regions. PHP's serialize() emits binary content around protected/private property markers (\x00*\x00, \x00ClassName\x00) that is not valid UTF-8. MySQL's utf8mb4 charset rejects these sequences:

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xDB\xE2\x88\xB2...' for column 'region'

PostgreSQL and SQLite don't enforce UTF-8 on text columns, so they're unaffected.

Fix

Wrap the serialized string with base64_encode/base64_decode in DatabaseSession so the value written to MySQL is always pure ASCII. This matches the workaround documented in the issue.

This was chosen over changing the column type to binary/blob because a schema change would require a new migration for every existing install that has already run statamic:nocache:migration. The ~33% base64 size overhead is negligible against a LONGTEXT column (4 GB ceiling) and typical region payload sizes.

The cache-backed Session path is unchanged — Redis/memcached/file stores don't enforce UTF-8.

jasonvarga and others added 3 commits April 16, 2026 10:05
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jasonvarga jasonvarga merged commit 7793b07 into 6.x Apr 16, 2026
17 checks passed
@jasonvarga jasonvarga deleted the fix-nocache-mysql-utf8 branch April 16, 2026 14:50
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.

Nocache storing serialized regions fails on MySQL due to invalid UTF-8

1 participant