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

Exclude heading row when limiting imported rows #4217

Open
wants to merge 3 commits into
base: 3.1
Choose a base branch
from

Conversation

jivanf
Copy link

@jivanf jivanf commented Oct 13, 2024

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?

This fixes #3439, which occurred because the heading row is included in LimitFilter by setting 1 as the starting row, which is the heading row when the WithHeadingRow concern is used.

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

No. The PR only contains 1 commit.

3️⃣ Does it include tests, if possible?

Yes.

4️⃣ Any drawbacks? Possible breaking changes?

Some projects might rely on the current behavior. For example, they might add 1 to their desired limit and ignore the empty row. With this PR, that row could now have data which shouldn't be imported.

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! 🙌

@jivanf jivanf force-pushed the fix-limit-import-with-heading-row branch from 453803b to fb49cdf Compare October 13, 2024 01:42
*/
public function array(array $array)
{
Assert::assertCount(1, $array);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we test here the exact contents of the array to be sure that it give the right now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous version returned an empty array when the limit was 1, which is why I just tested the length of the array, but I see now that the test could return a false positive in the future if, for example, an array with a single null value was returned instead. I'll change that.

Now that I'm thinking about it, a test with a limit of 2 should probably be added as well. When the limit was 2+, all the rows were imported except the last one, which was imported with null values, as the original issue reported. Currently, the test covers that case too, but it'd be safer to have another test for it.

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]: Using WithLimit getting last record with null values
2 participants