archtechx / tenancy

Automatic multi-tenancy for Laravel. No code changes needed.
https://tenancyforlaravel.com
MIT License
3.67k stars 431 forks source link

3.8.5 Possible regression in injecting tenant models into queued jobs #1260

Open stancl opened 1 month ago

stancl commented 1 month ago

Bug description

The changes made in https://github.com/archtechx/tenancy/pull/1251 have made injecting tenant models into queued jobs not work again, as in older versions of v3.

Steps to reproduce

Inject a tenant-context model into a queued job.

Expected behavior

Should be supported.

Laravel version

any

stancl/tenancy version

3.8.5

stancl commented 1 month ago

This has been reported but I can't seem to reproduce the bug myself in a fresh Laravel 11 app. Will appreciate any testing.

nicolay12866 commented 1 month ago

Hi, I do have this problem when queueing batches for one tenant (300-400 jobs) with a lot of data using laravel 10.48.22 and php 8.2.19 and on our test server with php 8.2.23. After 10 or so jobs it starts failing for the rest of them. For me reverting to tenancy 3.8.4 gets our environment running again.

stancl commented 1 month ago

Job batches aren't supported in v3 (maybe the support is flaky rather than completely missing?). We've added a bootstrapper in v4 to address that. So it's possible that the < 3.8.5 behavior made them work in your case for some reason?

Can you reproduce this using pure jobs without batches?

nicolay12866 commented 1 month ago

I can confirm that it works when I just dispatch them immediately instead of batching them

viicslen commented 1 week ago

The update also breaks compatibility with the following packagej https://github.com/Sammyjo20/laravel-chunkable-jobs

Trace of how jobs are dispatched https://github.com/Sammyjo20/laravel-chunkable-jobs/blob/5aa979e2ed64c8e8b7c9c3fb630db9f45ba0cc41/src/ChunkableJob.php#L77 https://github.com/Sammyjo20/laravel-chunkable-jobs/blob/5aa979e2ed64c8e8b7c9c3fb630db9f45ba0cc41/src/ChunkableJob.php#L148 https://github.com/Sammyjo20/laravel-chunkable-jobs/blob/5aa979e2ed64c8e8b7c9c3fb630db9f45ba0cc41/src/ChunkableJob.php#L157-L167

I know compatibility with a third party package is not really a that important or something that should be fixed, I just wanted to report it and maybe help gather more details about different scenarios