500 error from duplicate ID in collection tree following reorder of entries
Bug description
Reordering a new entry causes a duplicate ID in the collection tree.
Similar to #2662 (closed) and #9531 (open).
How to reproduce
NB: I'm struggling to recreate this in my dev env. The client has managed to cause the issue a couple of times but not entirely sure what is triggering it.
Steps:
- Create a new entry in an orderable collection and publish it.
- Reorder the entries and save.
- Result: 500 error on front-end that doesn't use custom error template
Only certain users seem to cause this issue:
- Their preferences & permissions are the same apart from collection listing columns being displayed
- Users on Windows 11 using Chrome.
- Workaround seems to be: refresh the collection listing (ie:
cmd + rin the browser) after publishing the new entry but before reordering.
Logs
No response
Environment
Environment
Application Name: Red + White
Laravel Version: 11.34.1
PHP Version: 8.3.13
Composer Version: 2.8.3
Environment: production
Debug Mode: OFF
URL: redandwhite.co
Maintenance Mode: OFF
Timezone: UTC
Locale: en
Cache
Config: CACHED
Events: CACHED
Routes: CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file
Statamic
Addons: 1
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.40.0 PRO
Statamic Addons
jacksleight/statamic-bard-mutator: 3.0.3
Installation
Fresh statamic/statamic site via CLI
Additional details
Further context:
- List of entries in the tree includes a duplicate ID at the end after using
Reorderbutton in the CP. - Results in
500error on the front-end (see below)- NB:
APP_DEBUG=falseso I presume the custom error template/resources/views/errors/500.blade.phpshould be presented instead?
- NB:
- Results in Server error in CP listing for that collection but no further info
- The duplicate ID CP page doesn't appear. I presume as it's not a duplicate entry in the collection, but a duplicate entry in the tree.
- The position of the newly created entry seems random. Sometimes it's at the top of the listing (desired) and sometimes at the bottom.
front-end error screenshot
CP error screenshot
Update: I think this is due to the user's choice with the number of entries to include in the pagination in the CP. Users that cause the issue have this set to 50 (default) and there are more than 50 entries in the collection. Changing 100 fixes it.
preferences:
collections:
projects:
per_page: 100
This happens when pagination is enabled on the sort page. It duplicates all entries on the active page in to to the trees yaml.
When this happens you cant solve it other then removing the duplicates manually.
It can be directed to this specific line:
https://github.com/statamic/cms/blob/5.x/src/Structures/CollectionStructure.php#L72
When this exception is removed the file gets fixed duplicates get removed and you don't get the broken list view. I'm not sure if this is the correct solution i don't know if there is a specific reasoning for this.
Problem lies actually in https://github.com/statamic/cms/blob/4e2ca8257c34280456ac6f134e724783d7747a83/src/Http/Controllers/CP/Collections/ReorderEntriesController.php#L33