cms
cms copied to clipboard
Reordering collection with filter applied breaks the tree structure and stache
Bug description
When a collection tree structure is saved, while a filter was applied, it breaks the tree structure and stache, resulting in errors.
These are the last lines of the pages.yaml after saving. There was a toast with 'Something went wrong' but it does update the trees file with this structure:
-
entry: 9da8f777-edb6-423a-8057-f9f86f60784f
- { }
How to reproduce
- Enable a filter on a collection table view
- Click on reorder
- When the CP switches to ordering state:
- The first view is still the filtered list but there is a loading bar on top.
- When the loader is finished it jumps back to the total collection listing (no filters applied). This can take a while with big collections.
- If you try to change the order and save before the list has turned back into the complete entries list, it fails.
- It should probably not be possible to click on Save when the listing is still loading (or even better, it should allow to order within a filtered state, but I can imagine that is harder to achieve)
- Check the trees file of the collection and see one or more lines with
- { }are added - When I remove these lines it works again
After the error Toast has popped up when clicking on save it throws this error when running php artisan statamic:stache:warm:
array_flip(): Can only flip string and integer values, entry skipped
Logs
Log of saving error:
"exception": "[object] (ErrorException(code: 0): Undefined array key \"entry\" at /home/ploi/www.example.com/vendor/statamic/cms/src/Structures/CollectionTreeDiff.php:40)
[stacktrace]
#0 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(255): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 /home/ploi/www.example.com/vendor/statamic/cms/src/Structures/CollectionTreeDiff.php(40): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(627): Statamic\\Structures\\CollectionTreeDiff->Statamic\\Structures\\{closure}()
#3 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(826): Illuminate\\Support\\Arr::mapWithKeys()
#4 /home/ploi/www.example.com/vendor/statamic/cms/src/Structures/CollectionTreeDiff.php(39): Illuminate\\Support\\Collection->mapWithKeys()
#5 /home/ploi/www.example.com/vendor/statamic/cms/src/Structures/CollectionTreeDiff.php(34): Statamic\\Structures\\CollectionTreeDiff->flatten()
#6 /home/ploi/www.example.com/vendor/statamic/cms/src/Structures/CollectionTreeDiff.php(21): Statamic\\Structures\\CollectionTreeDiff->prepare()
#7 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(355): Statamic\\Structures\\CollectionTreeDiff->analyze()
#8 /home/ploi/www.example.com/vendor/statamic/cms/src/Structures/CollectionTree.php(66): Illuminate\\Support\\Facades\\Facade::__callStatic()
#9 /home/ploi/www.example.com/vendor/statamic/cms/src/Entries/UpdateStructuredEntryOrderAndParent.php(13): Statamic\\Structures\\CollectionTree->diff()
#10 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(478): Statamic\\Entries\\UpdateStructuredEntryOrderAndParent->handle()
#11 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(286): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}()
#12 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(266): Illuminate\\Events\\Dispatcher->invokeListeners()
#13 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(433): Illuminate\\Events\\Dispatcher->dispatch()
#14 /home/ploi/www.example.com/vendor/statamic/cms/src/Events/Event.php(21): event()
#15 /home/ploi/www.example.com/vendor/statamic/cms/src/Structures/CollectionTree.php(46): Statamic\\Events\\Event::dispatch()
#16 /home/ploi/www.example.com/vendor/statamic/cms/src/Structures/Tree.php(170): Statamic\\Structures\\CollectionTree->dispatchSavedEvent()
#17 /home/ploi/www.example.com/vendor/statamic/cms/src/Http/Controllers/CP/Collections/ReorderEntriesController.php(46): Statamic\\Structures\\Tree->save()
The complete tree yaml file:
tree:
-
entry: 7f8e7917-3938-476b-9a8d-da8755cf1e1b
-
entry: 49bab4c1-70a1-4978-a0ba-f99618b8d098
-
entry: 58da0947-e25f-45ea-adb1-400da5b5c8dd
-
entry: 1e56bc73-12ef-4f70-bb6e-0682125cd79c
-
entry: 9039731f-83fe-408d-b185-cd2bbc63cad6
-
entry: 34737712-7ddc-428c-b708-94780afa74d8
-
entry: 09d9b5f7-ad7c-479d-901c-ef5e703e7e10
-
entry: 4af659b8-ab1f-45e7-a8b5-d94fff3574d8
-
entry: 077174ec-5528-4a81-81bd-59f8a1ea9ba7
-
entry: 0bd51ab5-bd88-4dba-8c2a-669e857184b6
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
- { }
Logs after saving:
[previous exception] [object] (ErrorException(code: 0): array_flip(): Can only flip string and integer values, entry skipped at /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Collection.php:426)
[stacktrace]
#0 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(255): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(426): array_flip()
#3 /home/ploi/www.example.com/vendor/statamic/cms/src/Entries/Entry.php(512): Illuminate\\Support\\Collection->flip()
#4 /home/ploi/www.example.com/vendor/statamic/cms/src/Data/AbstractAugmented.php(141): Statamic\\Entries\\Entry->order()
#5 /home/ploi/www.example.com/vendor/statamic/cms/src/Fields/Value.php(56): Statamic\\Data\\AbstractAugmented->Statamic\\Data\\{closure}()
#6 /home/ploi/www.example.com/vendor/statamic/cms/src/Data/AbstractAugmented.php(78): Statamic\\Fields\\Value->resolve()
#7 /home/ploi/www.example.com/vendor/statamic/cms/src/Data/AbstractAugmented.php(52): Statamic\\Data\\AbstractAugmented->get()
#8 /home/ploi/www.example.com/vendor/statamic/cms/src/Fields/Value.php(56): Statamic\\Data\\AbstractAugmented->Statamic\\Data\\{closure}()
#9 /home/ploi/www.example.com/vendor/statamic/cms/src/Data/AugmentedCollection.php(53): Statamic\\Fields\\Value->resolve()
#10 [internal function]: Statamic\\Data\\AugmentedCollection->Statamic\\Data\\{closure}()
#11 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(600): array_map()
#12 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(778): Illuminate\\Support\\Arr::map()
#13 /home/ploi/www.example.com/vendor/statamic/cms/src/Data/AugmentedCollection.php(53): Illuminate\\Support\\Collection->map()
#14 /home/ploi/www.example.com/vendor/statamic/cms/src/Data/HasAugmentedInstance.php(35): Statamic\\Data\\AugmentedCollection->all()
#15 /home/ploi/www.example.com/vendor/statamic/cms/src/Tags/Locales.php(147): Statamic\\Entries\\Entry->toAugmentedArray()
#16 /home/ploi/www.example.com/vendor/statamic/cms/src/Tags/Locales.php(109): Statamic\\Tags\\Locales->getLocalizedData()
#17 [internal function]: Statamic\\Tags\\Locales->Statamic\\Tags\\{closure}()
#18 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(600): array_map()
#19 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(778): Illuminate\\Support\\Arr::map()
#20 /home/ploi/www.example.com/vendor/statamic/cms/src/Tags/Locales.php(108): Illuminate\\Support\\Collection->map()
#21 /home/ploi/www.example.com/vendor/statamic/cms/src/Tags/Locales.php(78): Statamic\\Tags\\Locales->addData()
#22 /home/ploi/www.example.com/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(746): Statamic\\Tags\\Locales->Statamic\\Tags\\{closure}()
#23 /home/ploi/www.example.com/vendor/statamic/cms/src/Tags/Locales.php(77): Illuminate\\Support\\Collection->pipe()
#24 /home/ploi/www.example.com/vendor/statamic/cms/src/Tags/Locales.php(31): Statamic\\Tags\\Locales->getLocales()
Environment
Environment
Application Name: XXX
Laravel Version: 10.48.22
PHP Version: 8.3.9
Composer Version: 2.8.8
Environment: production
Debug Mode: OFF
URL: www.example.com/
Maintenance Mode: OFF
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: CACHED
Views: CACHED
Drivers
Broadcasting: pusher
Cache: redis
Database: mysql
Logs: stack / daily, slack
Mail: mailgun
Queue: redis
Session: redis
Statamic
Addons: 6
Sites: 3 (Nederlands, English, Deutsch)
Stache Watcher: Enabled
Static Caching: half
Version: 5.29.0 PRO
Statamic Addons
aerni/advanced-seo: 2.9.3
heidkaemper/statamic-toolbar: 1.2.1
jacksleight/statamic-bard-texstyle: 3.3.1
mattrothenberg/statamic-mapbox-address: 0.9.0
mitydigital/statamic-logger: 2.3.0
statamic/collaboration: 1.0.0
Installation
Fresh statamic/statamic site via CLI
Additional details
Maybe updating will fix it, as it is currently on version 5.29.0 of Statamic. I haven't tested it on the most recent version yet.