statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.72k stars 510 forks source link

Error on Deployment: Call to a member function hasStructure() on null #2773

Closed aerni closed 3 years ago

aerni commented 3 years ago

Bug Description

I'm running into this error on every deploy. I always have to manually SSH into the server, php please stache:clear, and run the deployment again. No idea why this is happening.

I'm using Ploi to deploy. It's very similar to Forge. This is the deploy script:

git pull origin master

npm install
npm run production
echo "πŸ›  Assets built successfully!"

composer install --no-interaction --prefer-dist --optimize-autoloader
echo "πŸŽ› Composer dependencies installed successfully!"

echo "" | sudo -S service php7.4-fpm reload

echo "πŸš€ Application deployed!"

php artisan optimize
php please static:clear
php please stache:refresh

This is the stacktrace:

[2020-10-30 09:56:11] testing.ERROR: Call to a member function hasStructure() on null {"exception":"[object] (Error(code: 0): Call to a member function hasStructure() on null at /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/CollectionEntriesStore.php:130)
[stacktrace]
#0 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/CollectionEntriesStore.php(125): Statamic\\Stache\\Stores\\CollectionEntriesStore->removeEntryFromStructure()
#1 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/Store.php(223): Statamic\\Stache\\Stores\\CollectionEntriesStore->handleDeletedItem()
#2 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(230): Statamic\\Stache\\Stores\\Store->Statamic\\Stache\\Stores\\{closure}()
#3 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/Store.php(225): Illuminate\\Support\\Collection->each()
#4 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/Store.php(38): Statamic\\Stache\\Stores\\Store->handleFileChanges()
#5 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/CollectionsStore.php(81): Statamic\\Stache\\Stores\\Store->index()
#6 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Repositories/CollectionRepository.php(83): Statamic\\Stache\\Stores\\CollectionsStore->updateEntryUris()
#7 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Statamic\\Stache\\Repositories\\CollectionRepository->updateEntryUris()
#8 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Entries/Collection.php(337): Illuminate\\Support\\Facades\\Facade::__callStatic()
#9 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/CollectionsStore.php(94): Statamic\\Entries\\Collection->updateEntryUris()
#10 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/Store.php(84): Statamic\\Stache\\Stores\\CollectionsStore->handleFileChanges()
#11 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Repositories/CollectionRepository.php(26): Statamic\\Stache\\Stores\\Store->getItems()
#12 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Repositories/CollectionRepository.php(58): Statamic\\Stache\\Repositories\\CollectionRepository->all()
#13 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/spatie/blink/src/Blink.php(279): Statamic\\Stache\\Repositories\\CollectionRepository->Statamic\\Stache\\Repositories\\{closure}()
#14 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Support/Blink.php(18): Spatie\\Blink\\Blink->once()
#15 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Statamic\\Support\\Blink->__call()
#16 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Repositories/CollectionRepository.php(59): Illuminate\\Support\\Facades\\Facade::__callStatic()
#17 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Statamic\\Stache\\Repositories\\CollectionRepository->handles()
#18 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/EntriesStore.php(18): Illuminate\\Support\\Facades\\Facade::__callStatic()
#19 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stores/AggregateStore.php(70): Statamic\\Stache\\Stores\\EntriesStore->discoverStores()
#20 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php(60): Statamic\\Stache\\Stores\\AggregateStore->clear()
#21 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(230): Illuminate\\Support\\HigherOrderCollectionProxy->Illuminate\\Support\\{closure}()
#22 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php(61): Illuminate\\Support\\Collection->each()
#23 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stache.php(82): Illuminate\\Support\\HigherOrderCollectionProxy->__call()
#24 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Stache/Stache.php(91): Statamic\\Stache\\Stache->clear()
#25 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Statamic\\Stache\\Stache->refresh()
#26 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/statamic/cms/src/Console/Commands/StacheRefresh.php(23): Illuminate\\Support\\Facades\\Facade::__callStatic()
#27 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Statamic\\Console\\Commands\\StacheRefresh->handle()
#28 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#29 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#30 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#31 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Container/Container.php(596): Illuminate\\Container\\BoundMethod::call()
#32 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call()
#33 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/symfony/console/Command/Command.php(258): Illuminate\\Console\\Command->execute()
#34 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run()
#35 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/symfony/console/Application.php(920): Illuminate\\Console\\Command->run()
#36 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/symfony/console/Application.php(266): Symfony\\Component\\Console\\Application->doRunCommand()
#37 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/symfony/console/Application.php(142): Symfony\\Component\\Console\\Application->doRun()
#38 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\\Component\\Console\\Application->run()
#39 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run()
#40 /home/ploi/staging.rewe-group.at-deploy/staging.rewe-group.at/30102020_095529/please(37): Illuminate\\Foundation\\Console\\Kernel->handle()
#41 {main}
"} 

Environment

Statamic 3.0.21 Pro Laravel 8.11.2 PHP 7.4.11 aerni/zipper 1.2.0

duncanmcclean commented 3 years ago

I know it's not a permanent fix but you can replace the stache clear command with php artisan cache:clear. It'll clear the Laravel cache (and the Stache) without the stache error.

aerni commented 3 years ago

Ah sweet. Will try that. Did you run into this as well?

duncanmcclean commented 3 years ago

Yeah, I've ran into it in the past.

aerni commented 3 years ago

Your quick fix did it. php artisan cache:clear instead of php please stache:refresh.

github-actions[bot] commented 3 years ago

This issue has not had recent activity and has been marked as stale β€” by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me.

MrMooky commented 3 years ago

Even though I'm using php artisan cache:clear as well, this occasionally happens to me as well. I cannot even clear the cache manually from within Statamic. The only "fix" is to re-deploy the same code again. Really annoying and I fear going live with this bug in a few weeks.

Using Envoyer here with latest Laravel, Statamic and PHP 8.0.9 as of today.

helloiamlukas commented 2 years ago

Having the same issue here. Only re-deploy will fix it. Any ideas what causes this?

timkley commented 2 years ago

We also faced this same issue. What I noticed is that the webserver sometimes uses the old release-path of the previous release. This can be fixed by restarting Apache. I'm still investigating if it's the webserver or the PHP process itself.

But maybe this helps some of you.

helloiamlukas commented 2 years ago

@timkley Had the same problem, sometimes the old release-path was still used for some parts of the application.

Reloading php7.4-fpm after clearing the cache but before the cache warmup did the trick for me now.

timkley commented 2 years ago

Thanks, @helloiamlukas for your insight. We restart the Apache now after every deployment and didn't have the issue again. Our hoster doesn't provide an easy way to only reload PHP at this time through our CD pipeline so this will have to do the trick for now.

isarphilipp commented 2 years ago

We might have found the root cause and a solution here https://github.com/statamic/cms/issues/4628

isarphilipp commented 2 years ago

Also check this solution with composer https://github.com/statamic/cms/issues/3832