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

check if local path is valid before writing #4034

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

adamgoucher
Copy link
Contributor

fixes #4033

Please take note of our contributing guidelines: https://docs.laravel-excel.com/3.1/getting-started/contributing.html
Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.

1️⃣ Why should it be added? What are the benefits of this change?

When exporting a queued report, if the filesystems are different across members of the cluster doing the exporting, things can error as it writes the temporary file as it was on the first machine.

This addresses #4033

2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.

3️⃣ Does it include tests, if possible?

4️⃣ Any drawbacks? Possible breaking changes?

This was manually tested on our infrastructure and appears to work in both

  • a -> a
  • a -> b
    queue configurations.

5️⃣ Mark the following tasks as done:

  • Checked the codebase to ensure that your feature doesn't already exist.
  • Take note of the contributing guidelines.
  • Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • Added tests to ensure against regression.

6️⃣ Thanks for contributing! 🙌

@patrickbrouwers patrickbrouwers merged commit 0c5e75d into SpartnerNL:3.1 Nov 29, 2023
16 checks passed
@axyr
Copy link

axyr commented Dec 15, 2023

Can we get this change in a new release?😍

im having the same problem, and this would save my week :)....

@patrickbrouwers
Copy link
Member

I tagged the release

@axyr
Copy link

axyr commented Dec 15, 2023

Thank you!

@iancunicky
Copy link

Hi there @adamgoucher ,

Issue Summary
I'm encountering an issue with the maatwebsite/excel package in a multi container AWS setup environment with multiple app containers and multiple queue containers. The problem arises when excel is appending sheets by a queue container and trying to handle those temporary files, which causes an error related to missing zip members.

Context
The issue occurs in the file src/Writer.php with the following block of code:
if ($temporaryFile instanceof RemoteTemporaryFile && !$temporaryFile->existsLocally()) { $temporaryFile = resolve(TemporaryFileFactory::class) ->makeLocal(Arr::last(explode('/', $temporaryFile->getLocalPath()))); }
This code checks for the existence of a temporary file locally, but for some reason, it fails to find the file in my AWS setup.

Error Details
The specific error message thrown is:
Could not find zip member zip:///tmp/laravel-excellaravel-excel-ELBUhsXaTZtRsUBE41BnohIboW9RrY7q.xlsx#_rels\.rels

Stack Trace
Here is the complete stack trace for reference:
#0 /app/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php(427): PhpOffice\PhpSpreadsheet\Shared\File::assertFile('/tmp/laravel-ex...', '_rels/.rels') #1 /app/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/BaseReader.php(182): PhpOffice\PhpSpreadsheet\Reader\Xlsx->loadSpreadsheetFromFile('/tmp/laravel-ex...') #2 /app/vendor/maatwebsite/excel/src/Writer.php(141): PhpOffice\PhpSpreadsheet\Reader\BaseReader->load('/tmp/laravel-ex...') #3 /app/vendor/maatwebsite/excel/src/Jobs/AppendQueryToSheet.php(98): Maatwebsite\Excel\Writer->reopen(Object(Maatwebsite\Excel\Files\RemoteTemporaryFile), 'Xlsx') #4 /app/vendor/maatwebsite/excel/src/Jobs/Middleware/LocalizeJob.php(46): Maatwebsite\Excel\Jobs\AppendQueryToSheet->Maatwebsite\Excel\Jobs\{closure}(Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet)) #5 /app/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): Maatwebsite\Excel\Jobs\Middleware\LocalizeJob->Maatwebsite\Excel\Jobs\Middleware\{closure}() #6 /app/vendor/maatwebsite/excel/src/Jobs/Middleware/LocalizeJob.php(45): Maatwebsite\Excel\Jobs\Middleware\LocalizeJob->withLocale(NULL, Object(Closure)) #7 /app/vendor/maatwebsite/excel/src/Jobs/AppendQueryToSheet.php(93): Maatwebsite\Excel\Jobs\Midd... #8 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Maatwebsite\Excel\Jobs\AppendQueryToSheet->handle(Object(Maatwebsite\Excel\Writer)) #9 /app/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() #10 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure(Object(Closure)) #11 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure)) #12 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL) #13 /app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call(Array) #14 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet)) #15 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet)) #16 /app/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #17 /app/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(124): Illuminate\Bus\Dispatcher->dispatchNow(Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet), false) #18 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}(Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet)) #19 /app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet)) #20 /app/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(123): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #21 /app/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(71): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\SqsJob), Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet)) #22 /app/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(102): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\SqsJob), Array) #23 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(439): Illuminate\Queue\Jobs\Job->fire() #24 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(389): Illuminate\Queue\Worker->process('sqs', Object(Illuminate\Queue\Jobs\SqsJob), Object(Illuminate\Queue\WorkerOptions)) #25 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(176): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\SqsJob), 'sqs', Object(Illuminate\Queue\WorkerOptions)) #26 /app/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(139): Illuminate\Queue\Worker->daemon('sqs', 'Alpha-SQS-AIPQu...', Object(Illuminate\Queue\WorkerOptions)) #27 /app/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(122): Illuminate\Queue\Console\WorkCommand->runWorker('sqs', 'Alpha-SQS-AIPQu...') #28 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Queue\Console\WorkCommand->handle() #29 /app/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() #30 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure(Object(Closure)) #31 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure)) #32 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL) #33 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\Container\Container->call(Array) #34 /app/vendor/symfony/console/Command/Command.php(279): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle)) #35 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle)) #36 /app/vendor/symfony/console/Application.php(1047): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #37 /app/vendor/symfony/console/Application.php(316): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #38 /app/vendor/symfony/console/Application.php(167): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #39 /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(196): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #40 /app/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #41 {main}

Impact
This issue is affecting my environment by preventing the proper handling of temporary files, which is critical for processing and generating Excel files in a multi-container AWS setup.

Request
Could you please look into this issue? Any insights or fixes to ensure the temporary files are correctly found and handled in such an environment would be highly appreciated.

My temporary fix was to comment the entire block of code on file src/Writer.php from line 168 to 172 where the fix #4033 was provided.

Thank you for your attention to this matter.

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

Successfully merging this pull request may close these issues.

[Bug]: Error with queued exports when filesystems are different
4 participants