Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection: Nesting level too deep - recursive dependency? #1790

Closed
nilshoerrmann opened this issue May 20, 2019 · 40 comments

Comments

@nilshoerrmann
Copy link
Contributor

@nilshoerrmann nilshoerrmann commented May 20, 2019

We found this error multiple times in our server logs:

PHP Fatal error: Nesting level too deep - recursive dependency? in /www/kirby/src/Toolkit/Collection.php on line 922

The mentioned line is sorting the collection, see https://github.com/getkirby/kirby/blob/develop/src/Toolkit/Collection.php#L922. I cannot provide any deeper info why and when this happened but Sonja noted this on the forum:

I think a similar error has come up several times in different contexts and I’m pretty sure I’ve seen it recently but can’t find it at the moment.

This was the issue I was thinking of: Change status/Delete page: Error = Nesting level too deep - recursive dependency?

But that happened in the Panel and it seems to appear in different contexts, I’ve actually seen this error message myself recently, so it seems to have different causes.

See https://forum.getkirby.com/t/collection-nesting-level-too-deep-recursive-dependency/14270/2.

This is happening on Kirby 3.1.4 RC1 but might have occured before, too.

@adis-me

This comment has been minimized.

Copy link

@adis-me adis-me commented May 23, 2019

I have the same issue. I have installed the latest Kirby version 3.1.4.

I only get the error when I want to publish my new content called Recipe. So basically my blueprints work fine when not published, but soon as I publish it, I see the error. Interested in a sample project to reproduce?

@distantnative

This comment has been minimized.

Copy link
Contributor

@distantnative distantnative commented May 23, 2019

@adis-me Yes, a sample project would help a lot.

@adis-me

This comment has been minimized.

Copy link

@adis-me adis-me commented May 23, 2019

@distantnative Sorry, but I really assume I am misconfiguring the blueprints, but attached a sample project. You can log in with demo@example.com as username and pwd.

nesting-level-too-deep.zip

In this project I have this error when I publish the Recipes page to status Unlisted.

@texnixe

This comment has been minimized.

Copy link
Contributor

@texnixe texnixe commented May 23, 2019

@adis-me Both your sections/pages.yml and your sections/recipes.yml are missing the parentoption.

@adis-me

This comment has been minimized.

Copy link

@adis-me adis-me commented May 23, 2019

@adis-me Both your sections/pages.yml and your sections/recipes.yml are missing the parentoption.

Is this a mandatory option? Will it fix my error? Hmm, questions questions.. Why my blog setup works and this not. It is based on the Blog configuration as provided on the website.

@texnixe

This comment has been minimized.

Copy link
Contributor

@texnixe texnixe commented May 23, 2019

I have to correct myself. The problem is not the missing parent option but setting the sortBy option to date for all children (which would then be children of site), you have the problem that the sorting is messed up.

@adis-me

This comment has been minimized.

Copy link

@adis-me adis-me commented May 23, 2019

I have to correct myself. The problem is not the missing parent option but setting the sortBy option to date for all children (which would then be children of site), you have the problem that the sorting is messed up.

Strange that the sortBy is causing this error. All my pages - including child pages - have a valid date. Either way, I can confirm that removing sortBy is for me fixing this error message. Thanks for your help @texnixe

@texnixe

This comment has been minimized.

Copy link
Contributor

@texnixe texnixe commented May 23, 2019

Not in the example you provided. You are using this section in site.yml, so pages are the children of site: home, blog, recipes and error. None of these pages has a date field to sort by.

@distantnative

This comment has been minimized.

Copy link
Contributor

@distantnative distantnative commented May 28, 2019

Is this solved? Was it a blueprint error?

@nilshoerrmann

This comment has been minimized.

Copy link
Contributor Author

@nilshoerrmann nilshoerrmann commented May 28, 2019

No, we still don‘t know why this happened on our site.

@distantnative

This comment has been minimized.

Copy link
Contributor

@distantnative distantnative commented Jun 2, 2019

@nilshoerrmann Without any reproducible setup this will be hard to debug. Could you provide this?

@distantnative distantnative added this to the 3.2.1 milestone Jun 2, 2019
@nilshoerrmann

This comment has been minimized.

Copy link
Contributor Author

@nilshoerrmann nilshoerrmann commented Jun 2, 2019

No, sadly I can‘t. Would it ne possible to enhance the error message for now? Without knowing which collection causes this, it‘s hatd to find the source of the issue.

@lukasbestle

This comment has been minimized.

Copy link
Contributor

@lukasbestle lukasbestle commented Jun 2, 2019

That's unfortunately not possible as it's an internal PHP error.

@nilshoerrmann

This comment has been minimized.

Copy link
Contributor Author

@nilshoerrmann nilshoerrmann commented Jun 2, 2019

In this case let‘s close this issue and reopen it as soon as we have more context.

@distantnative distantnative removed this from the 3.2.1 milestone Jun 2, 2019
@texnixe

This comment has been minimized.

Copy link
Contributor

@texnixe texnixe commented Jun 6, 2019

Just came across this issue again in the forum, where sorting by date with identical dates caused the issue: https://forum.getkirby.com/t/sorting-pages-via-query-in-blueprint-throws-error-nesting-level-too-deep-recursive-dependency/14507/7

@nilshoerrmann nilshoerrmann reopened this Jun 6, 2019
@nilshoerrmann

This comment has been minimized.

Copy link
Contributor Author

@nilshoerrmann nilshoerrmann commented Jun 6, 2019

I can confirm that this also happens on a site where we sort by date and have duplicate dates.

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Aug 1, 2019

I reproduced on 3.2.3-RC.1 with following blueprint:

customSection:
    type: pages
    sortBy: anyField asc

Nesting level too deep - recursive dependency?

But title field works

sortBy: title asc

I realized that issued with same values as @nilshoerrmann said

@distantnative distantnative added this to the 3.2.4 milestone Aug 9, 2019
@bastianallgeier

This comment has been minimized.

Copy link
Contributor

@bastianallgeier bastianallgeier commented Aug 9, 2019

I'm really sorry, but I cannot reproduce this at all :( Nor with duplicate dates neither with the undefined field.

@distantnative

This comment has been minimized.

Copy link
Contributor

@distantnative distantnative commented Aug 9, 2019

Me neither. E.g. adding the following to the notes blueprint in the Starterkit:

customSection:
        type: pages
        sortBy: author asc

Works flawless for me.

If it still causes troubles for you, could you please provide a step-by-step guid to reproduce this with the Starterkit? Thanks.

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Aug 9, 2019

Here reproduce blueprint with Kirby 3.2.3 Starterkit:

/site/blueprints/sections/notes.yml

type: pages
headline: Notes
info: "{{ page.date.toDate('d.m.Y') }}"
empty: No notes yet
sortBy: date desc

I don't know why, but issue with parent and template properties. When you remove that properties, you will get the error.

@distantnative

This comment has been minimized.

Copy link
Contributor

@distantnative distantnative commented Aug 9, 2019

title: Notes
icon: 📖

columns:
  - width: 1/2
    sections:
      customsection:
        type: pages
        headline: Custom section
        info: "{{ page.date.toDate('d.m.Y') }}"
        empty: No notes yet
        sortBy: date desc

works for me on current master branch (so 3.2.3):

Screen Shot 2019-08-09 at 16 45 42

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

@bastianallgeier bastianallgeier commented Aug 9, 2019

Could that be a problem with different PHP versions, OS or anything else? Let's compare PHP versions, operating systems and servers.

PHP 7.2.10
macOS: Mojave
server: Apache
MAMP

@distantnative

This comment has been minimized.

Copy link
Contributor

@distantnative distantnative commented Aug 9, 2019

PHP 7.2.13
macOS Catalina beta
server Apache
Valet+

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Aug 9, 2019

Apache 2.4.37 x86
PHP 7.2.15 x86
Windows 10 x64
EasyPHP

I'll test in live centos server

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

@bastianallgeier bastianallgeier commented Aug 9, 2019

Might it be a Windows thing? @nilshoerrmann what are you using?

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Aug 9, 2019

Failed on live server too

Apache 2.4
PHP Version 7.3.8
CentOS 6.10

@bastianallgeier

This comment has been minimized.

Copy link
Contributor

@bastianallgeier bastianallgeier commented Aug 9, 2019

And it's really just the starterkit? No modifications other than the blueprint? That's soooo weird!

@texnixe

This comment has been minimized.

Copy link
Contributor

@texnixe texnixe commented Aug 9, 2019

No problem:

PHP 7.2.13
macOS Mojave
server Apache
Valet

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Aug 9, 2019

And it's really just the starterkit? No modifications other than the blueprint? That's soooo weird!

Yes, just starterkit without modifications. I'll track this down.

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Aug 9, 2019

In fact, the cause of the error appears in the console:

code: 1
details: null
exception: "Whoops\Exception\ErrorException"
file: "\EasyPHP\eds-www\test\kirby\1790\kirby\src\Toolkit\Collection.php"
line: 948
message: "Nesting level too deep - recursive dependency?"
status: "error"

https://github.com/getkirby/kirby/blob/master/src/Toolkit/Collection.php#L948

Issue with array_multisort() function and when i remove this line, error gone.

Btw, i have tested without spread operator like array_multisort($params), error gone too but sort wrong.

@nilshoerrmann

This comment has been minimized.

Copy link
Contributor Author

@nilshoerrmann nilshoerrmann commented Aug 9, 2019

Did you all make sure to have two pages published on the same day before testing? And I‘m not sure if the pages that are referenced in the section needed to have num:date in their blueprint.

I‘m using MAMP on MacOS Mojave. Can post the version numbers next week.

@texnixe

This comment has been minimized.

Copy link
Contributor

@texnixe texnixe commented Aug 9, 2019

Even with same dates (and times) I don't get the error.

@nilshoerrmann

This comment has been minimized.

Copy link
Contributor Author

@nilshoerrmann nilshoerrmann commented Aug 9, 2019

I‘ll check on my machine next week.

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Aug 9, 2019

Other reproduce blueprints for starterkit site.yml

customSection:
    type: pages
    sortBy: status asc
customSection:
    type: pages
    templates: 
        - about
        - home
        - default
        - photography
        - notes
    sortBy: status asc

customSection:
    type: pages
    templates: 
        - about
        - notes
        - photography
    sortBy: status asc
@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Aug 9, 2019

Live example while changing page status: "notes unlisted to listed"

type: pages
templates: 
    - about
    - notes
    - photography
sortBy: status asc

section

@neildaniels

This comment has been minimized.

Copy link
Contributor

@neildaniels neildaniels commented Aug 9, 2019

I've come across this error (or something very similar) previously. And, to be honest, it was an issue in Kirby 2 as well.

I've never seen it in the panel, but I have seen it when I had custom Page Models/custom StructureObjects that were being sorted (via ->sortBy()).

I haven't seen it in a while, but he were informal observations I made when I ran into these issues:

  • When Pages/StructureObjects were being sorted by a key that wasn't very unique (i.e., if you were sorting by something like name asc, if multiple items had the exact same name it would often throw this error). Sorting by something "guaranteed" to be unique like uid/uri would make the error go away.
  • If I was sorting things that had instance properties (see below) to cache data, those could potentially be issues. My code did not do anything on clone() to account for that, so that might have been an issue. Removing the instance property and having the value be computed each time would normally make the issue go away.
<?php

class ExamplePage extends Page {
    protected $cachedData = [];

    public function foo() {
        return $cachedData['foo'] = $cachedData['foo'] ?? $this->something();
    }
}
@afbora afbora mentioned this issue Aug 19, 2019
4 of 4 tasks complete
@bastianallgeier bastianallgeier removed this from the 3.2.4 milestone Aug 21, 2019
@lukasbestle lukasbestle added this to the 3.2.5 milestone Sep 13, 2019
@lukasbestle lukasbestle self-assigned this Sep 13, 2019
@bastianallgeier

This comment has been minimized.

Copy link
Contributor

@bastianallgeier bastianallgeier commented Sep 16, 2019

We finally have a solution. Thanks to @afbora and @lukasbestle for taking care of it! 👏

@nilshoerrmann

This comment has been minimized.

Copy link
Contributor Author

@nilshoerrmann nilshoerrmann commented Sep 16, 2019

Which branch do we have to check out to test the solution?

@distantnative

This comment has been minimized.

Copy link
Contributor

@distantnative distantnative commented Sep 16, 2019

@nilshoerrmann it's on the develop branch - keep in mind that you need to build the assets on that branch yourself (though for this specific bug not necessarily since only PHP code changed).

@nilshoerrmann

This comment has been minimized.

Copy link
Contributor Author

@nilshoerrmann nilshoerrmann commented Sep 16, 2019

Thanks for the reminder regarding the assets – I often forget about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.