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

issue with queuing emails #35235

Closed
lsmith77 opened this issue Nov 16, 2020 · 16 comments
Closed

issue with queuing emails #35235

lsmith77 opened this issue Nov 16, 2020 · 16 comments

Comments

@lsmith77
Copy link
Contributor

lsmith77 commented Nov 16, 2020

  • Laravel Version: v8.9.0
  • PHP Version: 7.3.24
  • ramsey/uuid: 4.1.1 (latest version)
  • Database Driver & Version:

Description:

I am using Laravel Spark, sending invitation emails (ie. using SendInvitation which in turn uses InviteUserEmail). This causes an exception as the $id is an instance of LazyUuidFromString and not a string/integer, which breaks inside \Illuminate\Queue\SerializesAndRestoresModelIdentifiers::restoreCollection().

I am opening the issue here because I suspect the issue isn't Spark specific.

Steps To Reproduce:

Invite a user to a team inside Laravel Spark

Hacky Fix

    protected function restoreCollection($value)
    {
        if (! $value->class || count($value->id) === 0) {
            return new EloquentCollection;
        }
        $collection = $this->getQueryForModelRestoration(
            (new $value->class)->setConnection($value->connection), $value->id
        )->useWritePdo()->get();
        if (is_a($value->class, Pivot::class, true) ||
            in_array(AsPivot::class, class_uses($value->class))) {
            return $collection;
        }
        $collection = $collection->keyBy->getKey();
        $collectionClass = get_class($collection);
        return new $collectionClass(
            collect($value->id)->map(function ($id) use ($collection) {
if ($id instanceof LazyUuidFromString) {
    $id = $id->serialize();
}
                return $collection[$id] ?? null;
            })->filter()
        );
    }`
```

@lsmith77
Copy link
Contributor Author

I am not sure if this is related to ramsey/uuid#327

@driesvints
Copy link
Member

Please post your jobs.

@lsmith77
Copy link
Contributor Author

It is a bit tricky .. as stated above, this is inside a Laravel Spark application, which is proprietary code, so I am not sure if I am allowed to share the code in a public ticket. so maybe even though I am fairly sure that the issue is inside the framework, I should rather discuss this with Laravel Spark maintainre?

@lsmith77
Copy link
Contributor Author

Maybe what I can say is that the Spark code assigns Uuid::uuid4() as the ID of the model being serialized here. This returns an instance of LazyUuidFromString. Is this not allowed? ie. would it be the responsibility of the Spark code to ensure that the ID is a string?

@driesvints
Copy link
Member

Hmm yeah it should be a scalar or at least have the option to be converted to a scalar. I'm talking this over with the team.

@lsmith77
Copy link
Contributor Author

ok thank you .. there are 4 places where a UUID is assigned during model creation, if you have access to the code you can find them with the following search:
https://github.com/laravel/spark-aurelius/search?q=Uuid%3A%3Auuid4%28%29

@lsmith77
Copy link
Contributor Author

Oh one more thing .. those places have not changed in a long time. So it was possible before to assign Uuid::uuid4() and indeed maybe the issue is a BC break inside the Ramsey UUID library.

@lsmith77
Copy link
Contributor Author

hmm yeah .. LazyUuidFromString seems to be new in 4.0 and it does not have __toString() method, which is probably why things worked before, ie. it was just converted to a string when needed automatically.

@lsmith77
Copy link
Contributor Author

ah no .. it does have a __toString()

@lsmith77
Copy link
Contributor Author

so indeed forcing the string cast fixes the issue as well return $collection[(string)$id] ?? null;

@themsaid
Copy link
Member

themsaid commented Nov 16, 2020

Invite a user to a team inside Laravel Spark

I can invite a user to a team inside Laravel Spark without problems. We haven't received a similar issue from other customers as well. You'll need to share more details on your issue.

@lsmith77
Copy link
Contributor Author

ok thx. do you also have ramsey/uuid 4.1+ ?

@themsaid
Copy link
Member

What's the full stack trace of the exception you get?

@themsaid
Copy link
Member

also what is InviteUserEmail ?

@lsmith77
Copy link
Contributor Author

ah damn indeed. this part is custom code.

anyway I have a work around, by simply forcing the id to be a string.

I will try to create a reproducable test case on plain Laravel to show the issue with using a model with UuidInterface instances as the ID while using the Queue. If I manage to do this then we can have a more productive discussion. Sorry for not doing this immediately. I clearly got confused about what is custom code and what is spark code.

closing the ticket for now until I have this reproducable test case.

@driesvints
Copy link
Member

@lsmith77 no worries. Thanks for raising this. Glad you got it sorted 👍

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

No branches or pull requests

3 participants