Skip to content
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

Binary attribute casting no longer works in new versions (works flawlessly with v13.5.1) #895

Closed
djibrilcolynat opened this issue Dec 30, 2023 · 5 comments · Fixed by #893
Labels

Comments

@djibrilcolynat
Copy link

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 10.28.0
Package version 13.6.3
PHP version 8.1.0

Actual Behaviour

Binary uuid started creating error "Json malformed (Errno: 5)" even with use of a custom attribute modifier to cast from bytes to string and string to bytes. It worked fine for months till I updated from v13.5.1 to v13.6.3. I downgraded to v13.5.1 and it started working back fine as expected.

Expected Behaviour

After investigation, it looks like my custom BinaryUuid::class is no longer called and the object to be casted into json still contains binary information. With v13.5.1 I can confirm that it my attribute modifiers is called to cast binary data into string

Steps to Reproduce

Here is the class I used in my models that have binary uuid (Dyryndra/Laravel-efficient-uuid):

`class BinaryUuid implements AttributeEncoder
{

public static function encode($value)
{
    if (blank($value)) {
        return null;
    }
    return Uuid::fromBytes($value)->toString();
}

public static function decode($value)
{
    if (blank($value)) {
        return null;
    }
    return Uuid::fromString(strtolower($value))->getBytes();
}

}`

And then I do this in Models:

protected $attributeModifiers = [ "id" => BinaryUuid::class, "withhold_of" => BinaryUuid::class, "slavery" => BinaryUuid::class, "pin" => RightRedactor::class ];

Possible Solutions

If you have any ideas on how to solve the issue, add them here, otherwise you can omit this part.

@djibrilcolynat
Copy link
Author

I am sure at 90% that my custom cipher class (BinaryUuid::class) I gave in attributeModifiers is no longer getting called. When I put die("CALLED") in the encode function, I can see the message printed in the debugger for the v13.5.1 but it doesn't show when I am under v13.6.3 which mean the function is not called to cast the binary data before attempting to store it, which create the Malformed UTF-8 characters error

@parallels999
Copy link

#884 (comment)

Seems like Duplicate of #885

@MortenDHansen
Copy link
Contributor

I have released 13.6.4 where the queue feature is disabled by default (as it should have been, sorry). I expect avoiding the serialization for queue should mitigate the problem. If not, let me know and stick to v13.5.1 in production.

@djibrilcolynat
Copy link
Author

Yes it works fine in v13.6.4. Serialization was the culprit.

@parallels999
Copy link

#893

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants