Repository navigation
Conversation
…ntry The blueprint cache key of an unsaved entry is built from spl_object_id(), but PHP recycles object ids as soon as an object is freed. A fresh unsaved entry can therefore find the blueprint of a dead entry from another collection in Blink and keep it; the eloquent driver then persists that handle and the entry throws BlueprintNotFoundException once it is loaded again. Hand out instance ids that are never reused instead. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
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.
Follow-up to #15509, which keys the blueprint cache of unsaved entries by
spl_object_id().The problem
PHP recycles object ids as soon as an object is freed. When an unsaved entry resolves its blueprint and is then garbage collected, the next entry that happens to receive the same object id finds that blueprint in Blink under
entry-obj-{id}-blueprintand returns it, even though it belongs to a different collection.Entry::blueprint()never reachesCollection::entryBlueprint()for that entry.With the eloquent driver this is persisted:
toModel()resolves the blueprint before the model has an id, so the foreign handle lands in theblueprintcolumn, and loading the entry afterwards throwsBlueprintNotFoundException("Blueprint [] not found" because the handle came from the cache, not from the entry's data).Reproduction on 6.35.1 (two collections,
pagesandprograms):In our test suite this showed up as three order-dependent failures after upgrading from 6.34.1.
The fix
Unsaved entries get an instance id from a counter that is never reused, instead of
spl_object_id(). Saved entries keep their id-based key. The new test resolves a blog entry's blueprint, frees the entry, and asserts that a freshly made product entry still resolves its own blueprint, in a loop so that an object id does get recycled. The test fails on6.xbefore this change and passes with it.This PR was prepared with an AI tool; the change and the test were reviewed and run locally (
tests/Data/Entries/EntryTest.php, 152 tests green).