laravel-ardent / ardent

Self-validating, secure and smart models for Laravel's Eloquent ORM
BSD 3-Clause "New" or "Revised" License
1.39k stars 211 forks source link

Maximum function nesting level of '250' reached, aborting! #281

Closed simplenotezy closed 8 years ago

simplenotezy commented 8 years ago

Having run 3.0.0 successfully, after recently updating using composer update I get the following error, when I do:

$model = My\Models\Model::find(1);

Returns:

Maximum function nesting level of '250' reached, aborting!

This worked before running composer update.

simplenotezy commented 8 years ago

Funny thing is, if I instead do:

$model = My\Models\Model::whereId(1)->first();

or

$model = My\Models\Model::findOrFail(1);

It works

simplenotezy commented 8 years ago

I have tried switching back to the initial 3.0.0 release, but the error is the same. Guess I haven't used ::find() for a while.

igorsantos07 commented 8 years ago

Guess I haven't used find in a while as well, @canfiax. Just so you know: activating throwOnFind prevents the loop, that's why I never saw it until now :) It seems the issue is explained on #283. See if it's fixed for you in 3.1.1!

rmarliere commented 8 years ago

I'm also having this error, but for the version 2.5.0. I had to rollback to version 2.4.2.

ManiacTwister commented 8 years ago

@igorsantos07 I have this problem too. I'm using version 3.3.0 and laravel 5.2 (Is it even supposed to work with 5.2?)

When i call find() (or all() and probably any other database action) i get memory exhaused because of a infinite loop:

LaravelArdent\\Ardent\\Ardent::find() /var/www/app/Http/Controllers/BlogController.php:27, 
LaravelArdent\\Ardent\\Ardent->__call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:914, 
Illuminate\\Database\\Eloquent\\Model->__call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:387, 
LaravelArdent\\Ardent\\Ardent->newQuery() /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3546, 
LaravelArdent\\Ardent\\Ardent->applyGlobalScopes() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:934, 
LaravelArdent\\Ardent\\Ardent->__call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:934, 
Illuminate\\Database\\Eloquent\\Model->__call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:387, 
LaravelArdent\\Ardent\\Ardent->newQuery() /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3546, 
LaravelArdent\\Ardent\\Ardent->applyGlobalScopes() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:934, 
LaravelArdent\\Ardent\\Ardent->__call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:934, 
[...]
igorsantos07 commented 8 years ago

@ManiacTwister, would you provide us with a gist of the affected model, the table structure, and the exact call you're making? I do use all() and find() but do not face those issues.

Igor Santos -- Desenvolvedor Web [enviado do meu celular] On 15 Jan 2016 15:00, "ManiacTwister" notifications@github.com wrote:

@igorsantos07 https://github.com/igorsantos07 I have this problem too. I'm using version 3.3.0 and laravel 5.2 (Is it even supposed to work with 5.2?)

When i call find() (or all() and probably any other database action) i get memory exhaused because of a infinite loop:

LaravelArdent\Ardent\Ardent::find() /var/www/app/Http/Controllers/BlogController.php:27, LaravelArdent\Ardent\Ardent->call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:914, Illuminate\Database\Eloquent\Model->call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:387, LaravelArdent\Ardent\Ardent->newQuery() /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3546, LaravelArdent\Ardent\Ardent->applyGlobalScopes() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:934, LaravelArdent\Ardent\Ardent->call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:934, Illuminate\Database\Eloquent\Model->call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:387, LaravelArdent\Ardent\Ardent->newQuery() /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3546, LaravelArdent\Ardent\Ardent->applyGlobalScopes() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:934, LaravelArdent\Ardent\Ardent->__call() /var/www/vendor/laravelbook/ardent/src/Ardent/Ardent.php:934, [...]

— Reply to this email directly or view it on GitHub https://github.com/laravel-ardent/ardent/issues/281#issuecomment-172015910 .

ManiacTwister commented 8 years ago

Here is the gist: https://gist.github.com/ManiacTwister/0dbb10dd67142e7e1000

michaelfarrow commented 8 years ago

I just ran into this issue myself. Looks like laravel/framework@ca15fe7317e6cf3a1a138893c804a9c4196904a5 removed applyGlobalScopes() and moved it's logic to newQuery() causing _call() on the Ardent and Eloquent models to loop.

ilyashtrikul commented 8 years ago

+1 Same problem. Please fix it. But i had infinite loop with $model->load('relation_name') method. Infinite loop in LaravelArdent\Ardent\Ardent class

public function newQuery($excludeDeleted = true) {
    ...
    return $this->applyGlobalScopes($builder); // loop in this calling
}
igorsantos07 commented 8 years ago

@weyforth got it right, the issue is in the snippet by @shtricul. This is a pretty small fix, related to changed in Laravel between 4 and 5. The weirdest thing is it only happens sometimes, when it should happen every time we do any kind of find, I think.

The fix will be published soon on 3.4.2, as this is a bugfix for an internal API. However, PLEASE use caution when updating, I'm not entire sure it would not bring any troubles with it.