Cms: PHP Notice – yii\base\ErrorException Undefined offset: 1

Created on 29 Jan 2020  Â·  26Comments  Â·  Source: craftcms/cms

After update i get this error

All 26 comments

Do you have a stack trace in your log files?

Do you have a stack trace in your log files?

Yes.

Stack trace:
#0 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\helpers\ProjectConfig.php(275): yii\base\ErrorHandler->handleError(8, 'Undefined offse...', 'C:\\Users\\bramb\\...', 275, Array)
#1 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\helpers\ProjectConfig.php(284): craft\helpers\ProjectConfig::unpackAssociativeArray(Array, true)
#2 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\helpers\ProjectConfig.php(254): craft\helpers\ProjectConfig::unpackAssociativeArray(Array)
#3 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\services\Plugins.php(1372): craft\helpers\ProjectConfig::unpackAssociativeArrays(Array)
#4 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\services\Plugins.php(206): craft\services\Plugins->_getPluginConfigData('feed-me')
#5 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\base\ApplicationTrait.php(1351): craft\services\Plugins->loadPlugins()
#6 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\console\Application.php(59): craft\console\Application->_postInit()
#7 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\base\BaseObject.php(109): craft\console\Application->init()
#8 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\base\Application.php(206): yii\base\BaseObject->__construct(Array)
#9 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\console\Application.php(89): yii\base\Application->__construct(Array)
#10 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\console\Application.php(48): yii\console\Application->__construct(Array)
#11 [internal function]: craft\console\Application->__construct(Array)
#12 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\di\Container.php(400): ReflectionClass->newInstanceArgs(Array)
#13 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\di\Container.php(159): yii\di\Container->build('craft\\console\\A...', Array, Array)
#14 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\BaseYii.php(365): yii\di\Container->get('craft\\console\\A...', Array, Array)
#15 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\bootstrap\bootstrap.php(245): yii\BaseYii::createObject(Array)
#16 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\bootstrap\console.php(43): require('C:\\Users\\bramb\\...')
#17 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\craft(21): require('C:\\Users\\bramb\\...')
#18 {main}
2020-01-29 11:07:15 [-][-][-][info][application] $_GET = []

Ah okay, that was fixed today. To fix this,change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#67d2a4aa7724189682897035c1b90baeb358ebf7 as 3.4.0.2",
  "...": "..."
}

Then run composer update.

And then perform the update again? I'm afraid there was a small oversight in how Project Config changes were migrated which borked plugin settings that used associative arrays.

Sorry about that!

"craftcms/cms": "dev-develop#67d2a4aa7724189682897035c1b90baeb358ebf7 as 3.4.0.2",

Still not working.

Did you perform the update on a pre-3.4 update database?

Did you perform the update on a pre-3.4 update database?

Yes i think so..

@BramBeekman in that case, can you send over the pre-update database, your composer.json, and composer.lock files to [email protected] and reference this issue, please?

@BramBeekman in that case, can you send over the pre-update database, your composer.json, and composer.lock files to [email protected] and reference this issue, please?

I'm not sure if i did, can you explain what it means?

I mean can you zip up your pre-update database (from the installation that was before you updated to 3.4.x) and send it over email to [email protected]. Also, please attach the composer.json and composer.lock files, so I can install the site locally and see what problem you're having. Make sure to mention this Github issue in the subject, so we know what that is all about :)

I mean can you zip up your pre-update database (from the installation that was before you updated to 3.4.x) and send it over email to [email protected]. Also, please attach the composer.json and composer.lock files, so I can install the site locally and see what problem you're having. Make sure to mention this Github issue in the subject, so we know what that is all about :)

Done

Closing this; we’ll get this resolved offline.

I'm getting this error as well (Craft 3.4.5). Looks like something went wrong when project config tried to store an associative array from a config file where the value was a function.

return [
    'geoLocationAutoRedirect' => true,
    'geoLocationRedirectMap' => [
        'example' => [ 'isEU' => function ($isEu) { return $isEu; } ],
        //                       ^ looks like this is causing the error
        'default' => '*',
    ],
];
2020-02-10 06:56:48 [-][-][44dee9d50e61b8684ab6d44a80fd7482][error][yii\base\ErrorException:8] yii\base\ErrorException: Undefined offset: 1 in /var/www/html/vendor/craftcms/cms/src/helpers/ProjectConfig.php:275
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php(74): yii\base\ErrorHandler->handleError(8, 'Undefined offse...', '/var/www/html/v...', 275)
#1 /var/www/html/vendor/craftcms/cms/src/helpers/ProjectConfig.php(275): craft\web\ErrorHandler->handleError(8, 'Undefined offse...', '/var/www/html/v...', 275, Array)
#2 /var/www/html/vendor/craftcms/cms/src/helpers/ProjectConfig.php(284): craft\helpers\ProjectConfig::unpackAssociativeArray(Array, true)
#3 /var/www/html/vendor/craftcms/cms/src/helpers/ProjectConfig.php(254): craft\helpers\ProjectConfig::unpackAssociativeArray(Array)
#4 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(1372): craft\helpers\ProjectConfig::unpackAssociativeArrays(Array)
#5 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(206): craft\services\Plugins->_getPluginConfigData('simplemap')
#6 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(1351): craft\services\Plugins->loadPlugins()
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(103): craft\web\Application->_postInit()
#8 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()
#9 /var/www/html/vendor/yiisoft/yii2/base/Application.php(206): yii\base\BaseObject->__construct(Array)
#10 /var/www/html/vendor/craftcms/cms/src/web/Application.php(91): yii\base\Application->__construct(Array)
#11 [internal function]: craft\web\Application->__construct(Array)
#12 /var/www/html/vendor/yiisoft/yii2/di/Container.php(400): ReflectionClass->newInstanceArgs(Array)
#13 /var/www/html/vendor/yiisoft/yii2/di/Container.php(159): yii\di\Container->build('craft\\web\\Appli...', Array, Array)
#14 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\web\\Appli...', Array, Array)
#15 /var/www/html/vendor/craftcms/cms/bootstrap/bootstrap.php(245): yii\BaseYii::createObject(Array)
#16 /var/www/html/vendor/craftcms/cms/bootstrap/web.php(51): require('/var/www/html/v...')
#17 /var/www/html/web/index.php(20): require('/var/www/html/v...')
#18 {main}

@Tam Hm yeah… that shouldn’t have been saved to begin with. Can you send your composer.json and composer.lock files, along with a database backup, over to [email protected]?

@brandonkelly That's sent, let me know if you need anything else!

This just happened to me in my local environment after I had removed a language-based site from the system, running Craft CMS version 3.4.15. The issue seems to have been caused by the associated row in the sites table remaining after the site delete.

Here's the table contents after the site had been deleted already:

image

As a result, code where the site IDs were being iterated over would throw this error. I was able to fix it by manually removing the dead site row from the sites table.

Hope this helps someone!

@mizziness Sites only get soft-deleted initially. Shouldn’t result in any errors though. Do you still have a database backup from before you went in and deleted that row? If so can you please send into [email protected]?

@mizziness Sites only get soft-deleted initially. Shouldn’t result in any errors though. Do you still have a database backup from before you went in and deleted that row? If so can you please send into [email protected]?

Apologies for the slow reply!

I do believe I may have the database backups from around then - I will go spelunking and see if a) I do and b) if I can recreate the issue - if so, I'll send it all over to you :) Thanks!

@brandonkelly People are seeing this issue here as well, when saving settings in the CP: https://github.com/riasvdv/craft-scout/issues/152.

I presume this is due to having complex data types in the config/scout.php file, and then project.yaml trying to write them to project.yaml?

For what it's worth, I've modified the function unpackAssociativeArray in the file ProjectConfig.php in order to get in working. Of course this is overwritten when composer packages are installed anew.

    public static function unpackAssociativeArray(array $array, bool $recursive = true): array
    {
        if (isset($array[ProjectConfigService::CONFIG_ASSOC_KEY])) {
            $associative = [];
            if (!empty($array[ProjectConfigService::CONFIG_ASSOC_KEY])) {
                foreach ($array[ProjectConfigService::CONFIG_ASSOC_KEY] as $items) {
                    if (sizeof($items) > 1) { // Necessary because of problem with Scout
                        $associative[$items[0]] = $items[1];
                    }
                }
            }
            $array = $associative;
        }

        if ($recursive) {
            foreach ($array as &$value) {
                if (is_array($value)) {
                    $value = static::unpackAssociativeArray($value, true);
                }
            }
        }

        return $array;
    }

What exactly is Scout doing with the project config that is messing things up?

@brandonkelly Scout isn't doing anything explicit with project config.

The setting that is causing the error is indices, which is only settable via config/scout.php: https://github.com/riasvdv/craft-scout/blob/master/src/models/Settings.php#L28, and is an array of objects (instances of https://github.com/riasvdv/craft-scout/blob/master/src/ScoutIndex.php).

When the settings are saved in the CP, the instances are converted to yaml, and then we get the unpackAssociativeArray error.

Ahh, gotcha.

The way Scout 2 is storing nested objects in its field settings would have been problematic even before project config.

I’ve just submitted riasvdv/craft-scout#162 which should fix this error going forward.

Thanks @brandonkelly.

Is/should there be something in the docs stating plugin settings shouldn't contain values like this, or should explicitly exclude them as you PR'd?

Probably! cc @mattstein

Added a note to the Plugin Settings page, @timkelty.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mccombs picture mccombs  Â·  3Comments

michel-o picture michel-o  Â·  3Comments

leigeber picture leigeber  Â·  3Comments

timkelty picture timkelty  Â·  3Comments

rynpsc picture rynpsc  Â·  3Comments