cms icon indicating copy to clipboard operation
cms copied to clipboard

Blank entry object created in collection tree(s)

Open AndrewHaine opened this issue 2 years ago • 1 comments

Bug description

Firstly, apologies for the vagueness of this issue - I'm hoping to update it with further details as I find out more.

I've found an issue on one of our sites after updating to Statamic 3.3.9 (from 3.2.24) where occasionally blank entries will be added to the collection tree file (we're the eloquent driver to store entries in the DB hence why the IDs are integers rather than UUIDs)

  -
    entry: 5
    children:
      -
        entry: 62
        children:
          -
            entry: 2122
          -
            entry: 2317
          - {  } 

Interestingly:

  • This only appears to be happening for the "pages" collection (currently)
  • We're running a multisite instance and it only happens for one "Site" at a time.

I can't currently replicate this reliably but this is what i've tried so far:

  • Deleting the origin entry and selecting "Delete" when asked what to do with the localized pages
  • Making an unrelated change in the CMS (The original git commit shows that an empty item was added when a user made a change to their user permissions)

I've attached the log for the error that occurs when empty items are present in the tree - perhaps the order() method on the Entry class could be updated to filter out these blank values?

statamic-3.3-collection-tree-issue.txt

How to reproduce

  • Update to Statamic 3.3.9 (from 3.2.24)
  • Make a change in the CMS
  • Observe that an empty object was added to a collection tree

Logs

No response

Versions

Statamic 3.3.9 Pro Laravel 8.83.10 PHP 8.0.18 doublethreedigital/duplicator 2.2.0 doublethreedigital/runway 2.3.5 edalzell/forma 1.1 optimoapps/statamic-bard-text-align 1.0.2 silentz/akismet 3.1.1 statamic/eloquent-driver dev-withcandour/patch-1 withcandour/aardvark-seo 2.0.24 withcandour/statamic-markdown-table 1.0.0-beta

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

regex (default)

Additional details

No response

AndrewHaine avatar Apr 29 '22 10:04 AndrewHaine

Following up as it looks like this is still an issue with multisite installations, I spotted #5441 which appears to show the same bug. Originally I was thinking this was an issue with us using the eloquent driver however the related issue appears to be using the file driver.

I've been unable to replicate this issue during normal testing but I have been able to force this bug by manually passing null as the second parameter to Statamic\Structures\Tree@appendTo(), my leading theory (again - sorry but i've not been able to replicate in normal testing) for this is if a page is moved and no match is returned from Statamic\Structures\Tree@removeFromInBranches() which would trigger this bug, however, we have had issues in the past with entries not being pulled from the cache correctly (again, this is rare and we've been unable to replicate in testing) which would also trigger this bug.

I'm thinking the fix should be to implement protection inside of appendTo() to ensure that the $page variable isn't null.

AndrewHaine avatar Sep 05 '22 16:09 AndrewHaine