You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// select without id$users = User::select("name")->lazyById(10);
foreach($usersas$user) {
// endless loop (generator) because lazyById will always return elements from the first page
}
So foreach will fall into endless loop and never ends if there are more than 1 page of results.
You can say that it's programmer's responsibility to include id in select but chunkById has this check and lazyById documentation doesn't say anything about id is required.
In the chunkById we have this code which verifies that response has id column.
$lastId = data_get($results->last(), $alias);
if ($lastId === null) {
thrownewRuntimeException("The chunkById operation was aborted because the [{$alias}] column is not present in the query result.");
}
It seems logical to me to add such a check to lazyById as well.
Steps To Reproduce
Create table with 100 records for example
// select without id$users = User::select("name")->lazyById(10);
foreach($usersas$user) {
// endless loop (generator) because lazyById will always return elements from the first page
}
The text was updated successfully, but these errors were encountered:
decadence
changed the title
lazyById doesn't check availability of id in database responselazyById doesn't check availability of id column in database response
Sep 14, 2023
decadence
changed the title
lazyById doesn't check availability of id column in database responselazyById doesn't check availability of id column in database response and silently ends up with endless loop
Sep 14, 2023
@crynobone What configuration do you mean? Did you read the issue? chunkById has this check, lazyById does not. This is inconsistent behaviour that leads to the endless loop.
Laravel Version
10.22.0
PHP Version
8.1.9
Database Driver & Version
MySQL 5.7.39 (Windows 11)
Description
If we use this code (we don't select
id
column):So
foreach
will fall into endless loop and never ends if there are more than 1 page of results.You can say that it's programmer's responsibility to include
id
in select butchunkById
has this check andlazyById
documentation doesn't say anything aboutid
is required.In the
chunkById
we have this code which verifies that response hasid
column.It seems logical to me to add such a check to
lazyById
as well.Steps To Reproduce
Create table with 100 records for example
The text was updated successfully, but these errors were encountered: