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

[Bug]: export generator made duplicate rows #4184

Open
1 task done
normatov07 opened this issue Aug 13, 2024 · 3 comments
Open
1 task done

[Bug]: export generator made duplicate rows #4184

normatov07 opened this issue Aug 13, 2024 · 3 comments

Comments

@normatov07
Copy link

normatov07 commented Aug 13, 2024

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1

What version of Laravel are you using?

10.10

What version of PHP are you using?

8.2

Describe your issue

When I use generator with lazy model query. it gives some duplicate rows instead real rows. the count of rows is equal with real ones but real rows is lost and some rows become duplicate.

class ListExportGenerator implements FromGenerator, WithHeadings, ShouldAutoSize
{
    use Exportable;

    protected $query;

    public function __construct($query)
    {
        $this->query = $query;
    }

    public function generator(): Generator
    {
        foreach ($this->query->lazy(200) as $item) {

       yield [
                $createdAt,
                $updatedAt,
                $this->getStatus(intval($item["status"] ?? "")),
            ];
           }
   }
 public function headings(): array
    {
        return [
            'Дата создания',
            'Дата изменения',
            'Статус',
        ];
    }

    protected function getStatus($status): string
    {
        return match ($status) {
            default => "Не активный",
        };
    }
}
```__

### How can the issue be reproduced?

I use yield with generator.

### What should be the expected behaviour?

It must contain real rows, not duplicate.
@normatov07 normatov07 added the bug label Aug 13, 2024
@patrickbrouwers
Copy link
Member

Why not just use FromQuery + WithMapping, it does the same as your example?

@normatov07
Copy link
Author

Why not just use FromQuery + WithMapping, it does the same as your example?

FromQuery, can I use this as lazy loading ? . I will test it later. For now I resolve it by FromCollection inter and prepareRows method.

@chatisk
Copy link

chatisk commented Sep 10, 2024

Why not just use FromQuery + WithMapping, it does the same as your example?

Because FromQuery, although it chunks the jobs according to the query's count (AppendQueryToSheet), Close Sheet is not optimised / adjusted for that use, leading to memory allocation exhaustion.

@stale stale bot added the stale label Nov 10, 2024
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