laravel-efficient-uuid icon indicating copy to clipboard operation
laravel-efficient-uuid copied to clipboard

Model save not casting UUID to binary?

Open schmoove opened this issue 3 years ago • 6 comments
trafficstars

Thank you for the great package. I'm struggling with a persisting issue and wondering what I'm missing. If I simply load a record from a model, change a property, and then save it, I get this exception:

b"SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'template_id' at row 1 (SQL: update documentsettemplate_id= fb3c3189-9e96-4283-98e2-f5f8e114370c,document.updated_at= 2022-03-10 20:48:38 whereid = §\x15cÍõ8M>Åeì¯k╗╚e)"

So the id is being cast correctly, but not the template_id. Thanks for your help.

Model:

public function uuidColumns(): array
    {
        return ['id', 'template_id'];
    }

protected $casts = [
        'id' => EfficientUuid::class,
        'template_id' => EfficientUuid::class
    ];

Controller:

$document = Document::whereUuid($id, 'id')->first();
$document->status = 'CANCELLED';
        try {
            $document->save();
        } catch (\Exception $e){
            dd($e->getMessage());
        }

schmoove avatar Mar 10 '22 20:03 schmoove

I've opened a PR against the laravel-model-uuid repo, but haven't been able to come up with a failing test case.

I've been unable to reproduce this in my testing, so if you can take a look there and see if we can come up with some failing tests, then we can work towards fixing this.

michaeldyrynda avatar Mar 17 '22 23:03 michaeldyrynda

Thanks, will do. Wasn’t sure if this was related to laravel-model-uuid or this package.

On Fri, 18 Mar 2022 at 12:56 PM, Michael Dyrynda @.***> wrote:

Are you able to open a PR against the laravel-model-uuid https://github.com/michaeldyrynda/laravel-model-uuid repo with a failing test case?

I've been unable to reproduce this in my testing https://github.com/michaeldyrynda/laravel-model-uuid/pull/116, so if you can take a look there and see if we can come up with some failing tests, then we can work towards fixing this.

— Reply to this email directly, view it on GitHub https://github.com/michaeldyrynda/laravel-efficient-uuid/issues/55#issuecomment-1071880800, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKCURP4EUUNI53A5CU2IDDVAPBDHANCNFSM5QNYYX5A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

schmoove avatar Mar 18 '22 04:03 schmoove

It's a horrible cyclic dependency I hope to solve in the next major version 😅

michaeldyrynda avatar Mar 18 '22 05:03 michaeldyrynda

OK, I think this is actually related to michaeldyrynda/laravel-nullable-fields. I was using this on my model, and had set culprit template_id column to "nullable" as follows:

protected $nullable = [
		'template_id',
];

Removing this, and saving the model casts template_id to binary as it should.

Perhaps an inconsistency between the two packages? Thanks for your help @michaeldyrynda

schmoove avatar Mar 18 '22 23:03 schmoove

Hmm, that’s curious. I wonder if the nullable package was causing the binary template_id to be cast to a string when it was being checked for null.

michaeldyrynda avatar Mar 19 '22 02:03 michaeldyrynda

I am getting the problem at generating a Token via $user->createToken()

Vito0912 avatar Mar 04 '23 20:03 Vito0912