studioespresso / craft-scout

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.
MIT License
81 stars 54 forks source link

[5.x] Scout causing NotInstantiableException #315

Closed martyspain closed 4 months ago

martyspain commented 4 months ago

The Craft 5 compatible version of Scout (5.0.0-beta.1 as of this writing) is causing Craft to throw a NotInstantiableException whenever a new field or section is created or edited in the CMS. The top-line exception looks like this:

Not instantiable – [yii\di\NotInstantiableException](https://www.yiiframework.com/doc-2.0/yii-di-notinstantiableexception.html)
Failed to instantiate component or class "craft\behaviors\CustomFieldBehavior".
↵
Caused by: ReflectionException
Class "craft\behaviors\CustomFieldBehavior" does not exist

The stack trace is long, but I've added it here to help show where Scout appears (lines 55-57):

ReflectionException: Class "craft\behaviors\CustomFieldBehavior" does not exist in /var/www/html/vendor/yiisoft/yii2/di/Container.php:507
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/di/Container.php(507): ReflectionClass->__construct('craft\\behaviors...')
#1 /var/www/html/vendor/yiisoft/yii2/di/Container.php(385): yii\di\Container->getDependencies('craft\\behaviors...')
#2 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\behaviors...', Array, Array)
#3 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\behaviors...', Array, Array)
#4 /var/www/html/vendor/yiisoft/yii2/base/Component.php(764): yii\BaseYii::createObject(Array)
#5 /var/www/html/vendor/yiisoft/yii2/base/Component.php(748): yii\base\Component->attachBehaviorInternal('customFields', Array)
#6 /var/www/html/vendor/yiisoft/yii2/base/Component.php(473): yii\base\Component->ensureBehaviors()
#7 /var/www/html/vendor/craftcms/cms/src/db/Query.php(55): yii\base\Component->hasEventHandlers('init')
#8 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\db\Query->init()
#9 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php(588): yii\base\BaseObject->__construct(Array)
#10 /var/www/html/vendor/craftcms/cms/src/elements/User.php(273): craft\elements\db\ElementQuery->__construct('craft\\elements\\...')
#11 /var/www/html/vendor/craftcms/cms/src/elements/User.php(552): craft\elements\User::find()
#12 /var/www/html/vendor/yiisoft/yii2/web/User.php(699): craft\elements\User::findIdentity(1)
#13 /var/www/html/vendor/craftcms/cms/src/web/User.php(452): yii\web\User->renewAuthStatus()
#14 /var/www/html/vendor/yiisoft/yii2/web/User.php(199): craft\web\User->renewAuthStatus()
#15 /var/www/html/vendor/craftcms/commerce/src/Plugin.php(1086): yii\web\User->getIdentity()
#16 [internal function]: craft\commerce\Plugin::craft\commerce\{closure}(Object(craft\events\DefineFieldLayoutFieldsEvent))
#17 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\events\DefineFieldLayoutFieldsEvent))
#18 /var/www/html/vendor/yiisoft/yii2/base/Component.php(650): yii\base\Event::trigger('craft\\models\\Fi...', 'defineNativeFie...', Object(craft\events\DefineFieldLayoutFieldsEvent))
#19 /var/www/html/vendor/craftcms/cms/src/models/FieldLayout.php(429): yii\base\Component->trigger('defineNativeFie...', Object(craft\events\DefineFieldLayoutFieldsEvent))
#20 /var/www/html/vendor/craftcms/cms/src/models/FieldLayout.php(350): craft\models\FieldLayout->getAvailableNativeFields()
#21 /var/www/html/vendor/yiisoft/yii2/base/Component.php(180): craft\models\FieldLayout->setTabs(Array)
#22 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(557): yii\base\Component->__set('tabs', Array)
#23 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(craft\models\FieldLayout), Array)
#24 /var/www/html/vendor/craftcms/cms/src/base/Model.php(78): yii\base\BaseObject->__construct(Array)
#25 [internal function]: craft\base\Model->__construct(Array)
#26 /var/www/html/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#27 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\models\\Fi...', Array, Array)
#28 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\models\\Fi...', Array, Array)
#29 /var/www/html/vendor/craftcms/cms/src/Craft.php(70): yii\BaseYii::createObject(Array, Array)
#30 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(1015): Craft::createObject(Array)
#31 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(850): craft\services\Fields->createLayout(Array)
#32 [internal function]: craft\services\Fields->craft\services\{closure}(Array, 18)
#33 /var/www/html/vendor/craftcms/cms/src/base/MemoizableArray.php(90): call_user_func(Object(Closure), Array, 18)
#34 /var/www/html/vendor/craftcms/cms/src/base/MemoizableArray.php(76): craft\base\MemoizableArray->normalizeByKey(18)
#35 [internal function]: craft\base\MemoizableArray->craft\base\{closure}(18)
#36 /var/www/html/vendor/craftcms/cms/src/base/MemoizableArray.php(76): array_map(Object(Closure), Array)
#37 /var/www/html/vendor/craftcms/cms/src/base/MemoizableArray.php(104): craft\base\MemoizableArray->normalize(Array)
#38 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(942): craft\base\MemoizableArray->all()
#39 /var/www/html/vendor/craftcms/cms/src/Craft.php(370): craft\services\Fields->getAllLayouts()
#40 /var/www/html/vendor/craftcms/cms/src/Craft.php(242): Craft::_fields()
#41 /var/www/html/vendor/craftcms/cms/src/Craft.php(205): Craft::_autoloadCustomFieldBehavior()
#42 [internal function]: Craft::autoload('craft\\behaviors...')
#43 /var/www/html/vendor/yiisoft/yii2/di/Container.php(507): ReflectionClass->__construct('craft\\behaviors...')
#44 /var/www/html/vendor/yiisoft/yii2/di/Container.php(385): yii\di\Container->getDependencies('craft\\behaviors...')
#45 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\behaviors...', Array, Array)
#46 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\behaviors...', Array, Array)
#47 /var/www/html/vendor/yiisoft/yii2/base/Component.php(764): yii\BaseYii::createObject(Array)
#48 /var/www/html/vendor/yiisoft/yii2/base/Component.php(748): yii\base\Component->attachBehaviorInternal('customFields', Array)
#49 /var/www/html/vendor/yiisoft/yii2/base/Component.php(473): yii\base\Component->ensureBehaviors()
#50 /var/www/html/vendor/craftcms/cms/src/db/Query.php(55): yii\base\Component->hasEventHandlers('init')
#51 /var/www/html/vendor/craftcms/cms/src/elements/db/EntryQuery.php(303): craft\db\Query->init()
#52 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\elements\db\EntryQuery->init()
#53 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php(588): yii\base\BaseObject->__construct(Array)
#54 /var/www/html/vendor/craftcms/cms/src/elements/db/EntryQuery.php(262): craft\elements\db\ElementQuery->__construct('craft\\elements\\...', Array)
#55 /var/www/html/vendor/craftcms/cms/src/elements/Entry.php(216): craft\elements\db\EntryQuery->__construct('craft\\elements\\...')
#56 /var/www/html/vendor/studioespresso/craft-scout/src/ScoutIndex.php(44): craft\elements\Entry::find()
#57 /var/www/html/vendor/studioespresso/craft-scout/src/ScoutIndex.php(49): rias\scout\ScoutIndex->__construct('videos_dev')
#58 /var/www/html/config/scout.php(33): rias\scout\ScoutIndex::create('videos_dev')
#59 /var/www/html/vendor/craftcms/cms/src/services/Config.php(289): include('/var/www/html/c...')
#60 /var/www/html/vendor/craftcms/cms/src/services/Config.php(281): craft\services\Config->_configFromFileInternal('/var/www/html/c...')
#61 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(933): craft\services\Config->getConfigFromFile('scout')
#62 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(233): craft\services\Plugins->createPlugin('scout', Array)
#63 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(1641): craft\services\Plugins->loadPlugins()
#64 /var/www/html/vendor/craftcms/cms/src/web/Application.php(110): craft\web\Application->_postInit()
#65 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()
#66 /var/www/html/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct(Array)
#67 [internal function]: yii\base\Application->__construct(Array)
#68 /var/www/html/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#69 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\web\\Appli...', Array, Array)
#70 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\web\\Appli...', Array, Array)
#71 /var/www/html/vendor/craftcms/cms/src/Craft.php(70): yii\BaseYii::createObject(Array, Array)
#72 /var/www/html/vendor/craftcms/cms/bootstrap/bootstrap.php(316): Craft::createObject(Array)
#73 /var/www/html/vendor/craftcms/cms/bootstrap/web.php(40): require('/var/www/html/v...')
#74 /var/www/html/web/index.php(11): require('/var/www/html/v...')
#75 {main}

Next yii\di\NotInstantiableException: Failed to instantiate component or class "craft\behaviors\CustomFieldBehavior". in /var/www/html/vendor/yiisoft/yii2/di/Container.php:509
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/di/Container.php(385): yii\di\Container->getDependencies('craft\\behaviors...')
#1 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\behaviors...', Array, Array)
#2 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\behaviors...', Array, Array)
#3 /var/www/html/vendor/yiisoft/yii2/base/Component.php(764): yii\BaseYii::createObject(Array)
#4 /var/www/html/vendor/yiisoft/yii2/base/Component.php(748): yii\base\Component->attachBehaviorInternal('customFields', Array)
#5 /var/www/html/vendor/yiisoft/yii2/base/Component.php(473): yii\base\Component->ensureBehaviors()
#6 /var/www/html/vendor/craftcms/cms/src/db/Query.php(55): yii\base\Component->hasEventHandlers('init')
#7 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\db\Query->init()
#8 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php(588): yii\base\BaseObject->__construct(Array)
#9 /var/www/html/vendor/craftcms/cms/src/elements/User.php(273): craft\elements\db\ElementQuery->__construct('craft\\elements\\...')
#10 /var/www/html/vendor/craftcms/cms/src/elements/User.php(552): craft\elements\User::find()
#11 /var/www/html/vendor/yiisoft/yii2/web/User.php(699): craft\elements\User::findIdentity(1)
#12 /var/www/html/vendor/craftcms/cms/src/web/User.php(452): yii\web\User->renewAuthStatus()
#13 /var/www/html/vendor/yiisoft/yii2/web/User.php(199): craft\web\User->renewAuthStatus()
#14 /var/www/html/vendor/craftcms/commerce/src/Plugin.php(1086): yii\web\User->getIdentity()
#15 [internal function]: craft\commerce\Plugin::craft\commerce\{closure}(Object(craft\events\DefineFieldLayoutFieldsEvent))
#16 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\events\DefineFieldLayoutFieldsEvent))
#17 /var/www/html/vendor/yiisoft/yii2/base/Component.php(650): yii\base\Event::trigger('craft\\models\\Fi...', 'defineNativeFie...', Object(craft\events\DefineFieldLayoutFieldsEvent))
#18 /var/www/html/vendor/craftcms/cms/src/models/FieldLayout.php(429): yii\base\Component->trigger('defineNativeFie...', Object(craft\events\DefineFieldLayoutFieldsEvent))
#19 /var/www/html/vendor/craftcms/cms/src/models/FieldLayout.php(350): craft\models\FieldLayout->getAvailableNativeFields()
#20 /var/www/html/vendor/yiisoft/yii2/base/Component.php(180): craft\models\FieldLayout->setTabs(Array)
#21 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(557): yii\base\Component->__set('tabs', Array)
#22 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(craft\models\FieldLayout), Array)
#23 /var/www/html/vendor/craftcms/cms/src/base/Model.php(78): yii\base\BaseObject->__construct(Array)
#24 [internal function]: craft\base\Model->__construct(Array)
#25 /var/www/html/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#26 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\models\\Fi...', Array, Array)
#27 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\models\\Fi...', Array, Array)
#28 /var/www/html/vendor/craftcms/cms/src/Craft.php(70): yii\BaseYii::createObject(Array, Array)
#29 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(1015): Craft::createObject(Array)
#30 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(850): craft\services\Fields->createLayout(Array)
#31 [internal function]: craft\services\Fields->craft\services\{closure}(Array, 18)
#32 /var/www/html/vendor/craftcms/cms/src/base/MemoizableArray.php(90): call_user_func(Object(Closure), Array, 18)
#33 /var/www/html/vendor/craftcms/cms/src/base/MemoizableArray.php(76): craft\base\MemoizableArray->normalizeByKey(18)
#34 [internal function]: craft\base\MemoizableArray->craft\base\{closure}(18)
#35 /var/www/html/vendor/craftcms/cms/src/base/MemoizableArray.php(76): array_map(Object(Closure), Array)
#36 /var/www/html/vendor/craftcms/cms/src/base/MemoizableArray.php(104): craft\base\MemoizableArray->normalize(Array)
#37 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(942): craft\base\MemoizableArray->all()
#38 /var/www/html/vendor/craftcms/cms/src/Craft.php(370): craft\services\Fields->getAllLayouts()
#39 /var/www/html/vendor/craftcms/cms/src/Craft.php(242): Craft::_fields()
#40 /var/www/html/vendor/craftcms/cms/src/Craft.php(205): Craft::_autoloadCustomFieldBehavior()
#41 [internal function]: Craft::autoload('craft\\behaviors...')
#42 /var/www/html/vendor/yiisoft/yii2/di/Container.php(507): ReflectionClass->__construct('craft\\behaviors...')
#43 /var/www/html/vendor/yiisoft/yii2/di/Container.php(385): yii\di\Container->getDependencies('craft\\behaviors...')
#44 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\behaviors...', Array, Array)
#45 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\behaviors...', Array, Array)
#46 /var/www/html/vendor/yiisoft/yii2/base/Component.php(764): yii\BaseYii::createObject(Array)
#47 /var/www/html/vendor/yiisoft/yii2/base/Component.php(748): yii\base\Component->attachBehaviorInternal('customFields', Array)
#48 /var/www/html/vendor/yiisoft/yii2/base/Component.php(473): yii\base\Component->ensureBehaviors()
#49 /var/www/html/vendor/craftcms/cms/src/db/Query.php(55): yii\base\Component->hasEventHandlers('init')
#50 /var/www/html/vendor/craftcms/cms/src/elements/db/EntryQuery.php(303): craft\db\Query->init()
#51 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\elements\db\EntryQuery->init()
#52 /var/www/html/vendor/craftcms/cms/src/elements/db/ElementQuery.php(588): yii\base\BaseObject->__construct(Array)
#53 /var/www/html/vendor/craftcms/cms/src/elements/db/EntryQuery.php(262): craft\elements\db\ElementQuery->__construct('craft\\elements\\...', Array)
#54 /var/www/html/vendor/craftcms/cms/src/elements/Entry.php(216): craft\elements\db\EntryQuery->__construct('craft\\elements\\...')
#55 /var/www/html/vendor/studioespresso/craft-scout/src/ScoutIndex.php(44): craft\elements\Entry::find()
#56 /var/www/html/vendor/studioespresso/craft-scout/src/ScoutIndex.php(49): rias\scout\ScoutIndex->__construct('videos_dev')
#57 /var/www/html/config/scout.php(33): rias\scout\ScoutIndex::create('videos_dev')
#58 /var/www/html/vendor/craftcms/cms/src/services/Config.php(289): include('/var/www/html/c...')
#59 /var/www/html/vendor/craftcms/cms/src/services/Config.php(281): craft\services\Config->_configFromFileInternal('/var/www/html/c...')
#60 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(933): craft\services\Config->getConfigFromFile('scout')
#61 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(233): craft\services\Plugins->createPlugin('scout', Array)
#62 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(1641): craft\services\Plugins->loadPlugins()
#63 /var/www/html/vendor/craftcms/cms/src/web/Application.php(110): craft\web\Application->_postInit()
#64 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()
#65 /var/www/html/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct(Array)
#66 [internal function]: yii\base\Application->__construct(Array)
#67 /var/www/html/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#68 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\web\\Appli...', Array, Array)
#69 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\web\\Appli...', Array, Array)
#70 /var/www/html/vendor/craftcms/cms/src/Craft.php(70): yii\BaseYii::createObject(Array, Array)
#71 /var/www/html/vendor/craftcms/cms/bootstrap/bootstrap.php(316): Craft::createObject(Array)
#72 /var/www/html/vendor/craftcms/cms/bootstrap/web.php(40): require('/var/www/html/v...')
#73 /var/www/html/web/index.php(11): require('/var/www/html/v...')
#74 {main}

I've experienced this error on a couple of Craft 5 sites, both using Scout 5.0.0-beta.1. In both cases, disabling the Scout plugin resolves the error, and re-enabling the plugin immediately causes the error to be thrown when a new field or section is created, or if an entry type is edited.

Steps to reproduce

  1. Create a new section in the CMS
  2. Create a new entry type for that section in the CMS
  3. Try to save the changes
  4. Observe the exception is thrown

Craft CMS version

5.2.6

Plugin version

5.0.0-beta.1

Multi-site?

No

janhenckens commented 4 months ago

Hey @martyspain - I think this was already fixed in in Craft 4 version through this PR, I totally forgot to also merge it for Craft 5.

I'll try to have a fix out this evening!

thom-moresoda commented 4 months ago

hey @janhenckens any update on a fix for this one?

janhenckens commented 4 months ago

@thom-moresoda @martyspain Sorry for the delay, the 4 version of Scout got pretty diverged since I tagged the latest 5 beta so I wanted to get them in line again and have tests running green before tagging a new 5 release.

That's all done now, including a fix for this, now available in 5.0.0!

thom-moresoda commented 4 months ago

nice one, thanks @janhenckens 👍 I've just updated & it looks to have fixed the error