Fix double-serialization of binary UUIDs in BelongsToMany relationships#38
Merged
kchung merged 9 commits intoWeebly:masterfrom Jan 22, 2026
Merged
Fix double-serialization of binary UUIDs in BelongsToMany relationships#38kchung merged 9 commits intoWeebly:masterfrom
kchung merged 9 commits intoWeebly:masterfrom
Conversation
kchung
reviewed
Jan 16, 2026
kchung
approved these changes
Jan 20, 2026
karim-square
approved these changes
Jan 20, 2026
kchung
reviewed
Jan 21, 2026
kchung
reviewed
Jan 21, 2026
8755127 to
161bdd9
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.
Summary
Problem
When using BelongsToMany relationships with binary UUID primary keys (via mutators), pivot operations like
updateExistingPivot(),sync(),attach(), anddetach()could fail with:Ramsey\Uuid\Exception\InvalidArgumentException: Incorrect UUID version
This occurs because
parseId()andparseIds()attempt to serialize values that are already in binary format. The existing cache check (in_array($value, $this->mutated_values)) only catches values serialized within the same instance, not binary values from other sources.Root Cause
This bug was introduced with the upgrade to
ramsey/uuid4.x (Laravel 7+). Version 4.x is stricter about UUID validation and throws an exception when attempting to parse binary data as a UUID string.Solution
Added a
ctype_print()check before serialization to detect already-binary values:ctype_print()returnstruectype_print()returnsfalse