Closed khalwat closed 1 year ago
This PR fixes this issue: https://github.com/craftcms/cms/pull/13920
Fixed for 4.6 via #13920 / d02708c52b1f570b37cc31fc8c4b58329e9a9fcd.
Craft 4.6.0 is out now with that change. Use with caution, though!
What's the caution, MariaDB issues?
Right
What happened?
Description
I have a custom Field that adds a
Schema::TYPE_JSON
content column type. Upon saving the field, the values in the field are double-encoded.Craft does this in the
saveContent()
method inContent
service: https://github.com/craftcms/cms/blob/develop/src/services/Content.php#L79...and then in
Db::prepareValueForDb()
it does this: https://github.com/craftcms/cms/blob/develop/src/helpers/Db.php#L128The problem is it isn't passing in the
$columnType
when callingDb::prepareValueForDb()
so it always encodes the value before passing it to Yii2... which then also encodes the value because it's a JSON column.So you end up with stored values that are double-encoded as JSON.
Here's the Field in question: https://github.com/lsst-epo/canto-dam-assets/blob/develop-v4/src/fields/CantoDamAsset.php
Steps to reproduce
Schema::TYPE_JSON
Expected behavior
The value will only be encoded once as JSON
Actual behavior
The value is actually doubly encoded as JSON
Craft CMS version
4.5.5
PHP version
n/a
Operating system and version
n/a
Database type and version
MySQL 8.0.32
Image driver and version
n/a
Installed plugins and versions
- n/a