craftcms / craftcms/cms

[5.6.9.1]: Find and replace command fails Array to string conversion type casting

Open
#16,751 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

Hi!

Had to make a huge search-replace in our project and it fails with the latest version in the corner of the type casting functions called before executing the update. I haven't had much time to pre-dig into it to help the diagnosis as I usually like to do, but it seems related to type casting the database before executing the update.

Steps to reproduce
  1. Create entries with "asdf" or any words inside a sub-matrix block.
  2. Use the admin interface "Find and replace" utility and search "asdf" to change it to "whatever"
  3. The queue manager outputs the error
Expected behavior

Search and replace should go through.

Actual behavior

It seems to fail at type casting, maybe some of the array or json types?

Stack trace
[queue.ERROR] [craft\queue\QueueLogBehavior::afterError]  [93652] Replacing “asdf” with “whatever” (batch 1 of 3) (attempt: 1, pid: 99598) - Error (time: 0.727s): Array to string conversion {"memory":5160368} 
[queue.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Array to string conversion in vendor/yiisoft/yii2/db/ColumnSchema.php:173
Stack trace:
[queue.ERROR] [craft\queue\QueueLogBehavior::afterError]  [93652] Replacing “asdf” with “whatever” (batch 1 of 3) (attempt: 1, pid: 99598) - Error (time: 0.727s): Array to string conversion {"memory":5160368} 
[queue.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Array to string conversion in vendor/yiisoft/yii2/db/ColumnSchema.php:173
Stack trace:
#0 vendor/craftcms/cms/src/web/ErrorHandler.php(115): yii\base\ErrorHandler->handleError(2, 'Array to string...', '...', 173)
#1 vendor/yiisoft/yii2/db/ColumnSchema.php(173): craft\web\ErrorHandler->handleError(2, 'Array to string...', '...', 173)
#2 vendor/craftcms/cms/src/db/mysql/ColumnSchema.php(36): yii\db\ColumnSchema->typecast(Array)
#3 vendor/yiisoft/yii2/db/mysql/ColumnSchema.php(49): craft\db\mysql\ColumnSchema->typecast(Array)
#4 vendor/yiisoft/yii2/db/QueryBuilder.php(651): yii\db\mysql\ColumnSchema->dbTypecast(Array)
#5 vendor/yiisoft/yii2/db/QueryBuilder.php(630): yii\db\QueryBuilder->prepareUpdateSets('{{%elements_sit...', Array, Array)
#6 vendor/yiisoft/yii2/db/Command.php(598): yii\db\QueryBuilder->update('{{%elements_sit...', Array, Array, Array)
#7 vendor/craftcms/cms/src/db/Command.php(152): yii\db\Command->update('{{%elements_sit...', Array, Array, Array)
#8 vendor/craftcms/cms/src/helpers/Db.php(1116): craft\db\Command->update('{{%elements_sit...', Array, Array, Array, false)
#9 vendor/craftcms/cms/src/queue/jobs/FindAndReplace.php(61): craft\helpers\Db::update('{{%elements_sit...', Array, Array, Array, false)
#10 vendor/craftcms/cms/src/queue/BaseBatchedJob.php(137): craft\queue\jobs\FindAndReplace->processItem(Array)
#11 vendor/yiisoft/yii2-queue/src/Queue.php(243): craft\queue\BaseBatchedJob->execute(Object(craft\queue\Queue))
#12 vendor/yiisoft/yii2-queue/src/cli/Queue.php(147): yii\queue\Queue->handleMessage(93652, 'O:31:"craft\\que...', 300, 1)
#13 vendor/craftcms/cms/src/queue/Queue.php(192): yii\queue\cli\Queue->handleMessage(93652, 'O:31:"craft\\que...', 300, 1)
#14 vendor/craftcms/cms/src/queue/Queue.php(167): craft\queue\Queue->executeJob()
#15 [internal function]: craft\queue\Queue->craft\queue\{closure}(Object(Closure))
#16 vendor/yiisoft/yii2-queue/src/cli/Queue.php(114): call_user_func(Object(Closure), Object(Closure))
#17 vendor/craftcms/cms/src/queue/Queue.php(165): yii\queue\cli\Queue->runWorker(Object(Closure))
#18 vendor/craftcms/cms/src/controllers/QueueController.php(98): craft\queue\Queue->run()
#19 vendor/craftcms/cms/src/controllers/QueueController.php(118): craft\controllers\QueueController->actionRun()
#20 [internal function]: craft\controllers\QueueController->actionRetry()
#21 vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#22 vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#23 vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('retry', Array)
#24 vendor/craftcms/cms/src/web/Application.php(361): yii\base\Module->runAction('queue/retry', Array)
#25 vendor/craftcms/cms/src/web/Application.php(660): craft\web\Application->runAction('queue/retry', Array)
#26 vendor/craftcms/cms/src/web/Application.php(323): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#27 vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#28 web/index.php(12): yii\base\Application->run()
#29 {main} {"memory":5160640,"exception":"[object] (yii\\base\\ErrorException(code: 2): Array to string conversion at vendor/yiisoft/yii2/db/ColumnSchema.php:173)"} 
[queue.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Array to string conversion in vendor/yiisoft/yii2/db/ColumnSchema.php:173
Stack trace:
#0 vendor/craftcms/cms/src/web/ErrorHandler.php(115): yii\base\ErrorHandler->handleError(2, 'Array to string...', '...', 173)
#1 vendor/yiisoft/yii2/db/ColumnSchema.php(173): craft\web\ErrorHandler->handleError(2, 'Array to string...', '...', 173)
#2 vendor/craftcms/cms/src/db/mysql/ColumnSchema.php(36): yii\db\ColumnSchema->typecast(Array)
#3 vendor/yiisoft/yii2/db/mysql/ColumnSchema.php(49): craft\db\mysql\ColumnSchema->typecast(Array)
#4 vendor/yiisoft/yii2/db/QueryBuilder.php(651): yii\db\mysql\ColumnSchema->dbTypecast(Array)
#5 vendor/yiisoft/yii2/db/QueryBuilder.php(630): yii\db\QueryBuilder->prepareUpdateSets('{{%elements_sit...', Array, Array)
#6 vendor/yiisoft/yii2/db/Command.php(598): yii\db\QueryBuilder->update('{{%elements_sit...', Array, Array, Array)
#7 vendor/craftcms/cms/src/db/Command.php(152): yii\db\Command->update('{{%elements_sit...', Array, Array, Array)
#8 vendor/craftcms/cms/src/helpers/Db.php(1116): craft\db\Command->update('{{%elements_sit...', Array, Array, Array, false)
#9 vendor/craftcms/cms/src/queue/jobs/FindAndReplace.php(61): craft\helpers\Db::update('{{%elements_sit...', Array, Array, Array, false)
#10 vendor/craftcms/cms/src/queue/BaseBatchedJob.php(137): craft\queue\jobs\FindAndReplace->processItem(Array)
#11 vendor/yiisoft/yii2-queue/src/Queue.php(243): craft\queue\BaseBatchedJob->execute(Object(craft\queue\Queue))
#12 vendor/yiisoft/yii2-queue/src/cli/Queue.php(147): yii\queue\Queue->handleMessage(93652, 'O:31:"craft\\que...', 300, 1)
#13 vendor/craftcms/cms/src/queue/Queue.php(192): yii\queue\cli\Queue->handleMessage(93652, 'O:31:"craft\\que...', 300, 1)
#14 vendor/craftcms/cms/src/queue/Queue.php(167): craft\queue\Queue->executeJob()
#15 [internal function]: craft\queue\Queue->craft\queue\{closure}(Object(Closure))
#16 vendor/yiisoft/yii2-queue/src/cli/Queue.php(114): call_user_func(Object(Closure), Object(Closure))
#17 vendor/craftcms/cms/src/queue/Queue.php(165): yii\queue\cli\Queue->runWorker(Object(Closure))
#18 vendor/craftcms/cms/src/controllers/QueueController.php(98): craft\queue\Queue->run()
#19 vendor/craftcms/cms/src/controllers/QueueController.php(118): craft\controllers\QueueController->actionRun()
#20 [internal function]: craft\controllers\QueueController->actionRetry()
#21 vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#22 vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#23 vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('retry', Array)
#24 vendor/craftcms/cms/src/web/Application.php(361): yii\base\Module->runAction('queue/retry', Array)
#25 vendor/craftcms/cms/src/web/Application.php(660): craft\web\Application->runAction('queue/retry', Array)
#26 vendor/craftcms/cms/src/web/Application.php(323): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#27 vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#28 web/index.php(12): yii\base\Application->run()
#29 {main} {"memory":5163256,"exception":"[object] (yii\\base\\ErrorException(code: 2): Array to string conversion at vendor/yiisoft/yii2/db/ColumnSchema.php:173)"} 
Craft CMS version

5.6.9.1

PHP version

8.2.20 locally and 8.2.27 on remote

Operating system and version

MacOS Sequoia 15.3 locally and AlmaLinux 8.10 (Linux 4.18.0-553.30.1.el8_10.x86_64) on remote

Database type and version

MySQL 8.3.0 locally and 8.0.41 on remote

Image driver and version

GD 8.2.27 locally and GD 8.2.20 on remote

Installed plugins and versions
Name Handle Package Name Version Installed Enabled
Blocksmith blocksmith mediakreativ/craft-blocksmith dev-main Yes Yes
CKEditor ckeditor craftcms/ckeditor 4.6.0 Yes Yes
Colorit colorit presseddigital/colorit dev-master Yes Yes
Content Templates content-templates spicyweb/craft-content-templates 2.0.2 Yes Yes
Entry GPS Coordinates entry-gps-coordinates nthmedia/entry-gps-coordinates dev-master Yes Yes
Field Manager field-manager verbb/field-manager 4.0.3 Yes Yes
Formie formie verbb/formie 3.0.20 Yes Yes
Hyper hyper verbb/hyper 2.2.1 Yes Yes
Icon Picker icon-picker verbb/icon-picker 3.0.3 Yes Yes
Navigation navigation verbb/navigation 3.0.6 Yes Yes
oEmbed oembed wrav/oembed dev-feature/gql-params Yes Yes
Route Map route-map nystudio107/craft-routemap dev-craft-5 Yes Yes
SEOmatic seomatic nystudio107/craft-seomatic dev-develop-v5 Yes Yes
Smith smith verbb/smith 3.1.0 Yes Yes
Feed Me feed-me craftcms/feed-me 6.7.0 Yes No
Control Panel Nav cp-nav verbb/cp-nav 5.0.3 No No

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with craftcms/cms/src/queue/jobs/FindAndReplace.php at processItem(), then follow the update through craftcms/cms/src/helpers/Db.php:1116 and the reported Yii ColumnSchema typecasting path. Reproduce the admin Find and replace operation using an entry with a sub-matrix block. Done means the queue completes the replacement without an Array to string conversion error.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.