-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
\Illuminate\Database\Eloquent\Concerns\PreventsCircularRecursion::withoutRecursion()
method crashes on mocked models
#52727
Comments
Error messages from tests for context.
|
Thank you for reporting this issue! As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub. If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team. Thank you! |
Hi, I'm facing the same issue with laravel 11.24.1 on mocked model. protected function withoutRecursion($callback, $default = null)
{
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
$onceable = Onceable::tryFromTrace($trace, $callback);
if (is_null($onceable)) {
return call_user_func($callback);
}
$stack = static::getRecursiveCallStack($this);
// ... |
This seem to be fixed via #52943 Please submit new bug report if you still have any issue. |
Laravel Version
11.22.0
PHP Version
8.3.8
Database Driver & Version
No response
Description
Method
\Illuminate\Database\Eloquent\Concerns\PreventsCircularRecursion::withoutRecursion()
will crash if it is invoked from eval.Method definition
framework/src/Illuminate/Database/Eloquent/Concerns/PreventsCircularRecursion.php
Lines 25 to 46 in a2c66ad
That happens because
\Illuminate\Support\Onceable::tryFromTrace()
will returnnull
when the second frame in the trace stack iseval
.A more appropriate example is when the
\Illuminate\Database\Eloquent\Model::toArray()
method is called on a model mocked bymockery/mockery
.Real-world example.
Stack:
Our feature test:
The exception happens when Ineria middleware tries to pass the mocked user model to the front end.
Steps To Reproduce
I prepared two Pest tests that demonstrate this bug:
Repo: https://github.com/sanfair/laravel-prevent-circular-recursion-bug
Commit with tests: sanfair/laravel-prevent-circular-recursion-bug@89b173c
The text was updated successfully, but these errors were encountered: