Repository navigation
[13.x] Fix chunkById() and lazyById() looping forever on models with a cast primary key - #61816
Merged
Merged
Conversation
xurshudyan
force-pushed
the
chunk-by-id-cast-key
branch
from
October 2, 2026 05:24
5dc0a84 to
3bab133
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a model casts its key,
chunkById()andlazyById()read the last ID of each page through the cast. That means the value bound into the nextwhere id > ?query is the cast value, not the one stored in the database. WithAsBinary::uuid(), the next page binds a 36 character UUID string against a binary(16) column, gets the same rows back, and the loop never ends.For example, with
'id' => AsBinary::uuid()(the example from #58254),Model::chunkById(100, ...)keeps returning the first page with the same binding. The same happens ineachById(),lazyById(), andmodel:prune, sinceprunablemodels are chunked by ID too.This PR reads the raw attribute when the result is a model, so the next page is bound with the same value the database returned. Plain query builder results still go through data_get() as before.