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 for _per_page existence #6702

Merged
merged 1 commit into from
Dec 23, 2020
Merged

Check for _per_page existence #6702

merged 1 commit into from
Dec 23, 2020

Conversation

VincentLanglet
Copy link
Member

@VincentLanglet VincentLanglet commented Dec 12, 2020

Subject

I got this weird error recently.

I am targeting this branch, because BC.

Changelog

### Fixed
- Stop throwing an exception when the `_per_page`  filter parameter is not set

@VincentLanglet VincentLanglet requested a review from a team December 12, 2020 18:32
@franmomu
Copy link
Member

I got this weird error recently.

Why is it weird? Can you please add a test covering that case?

@franmomu franmomu added the patch label Dec 12, 2020
@VincentLanglet
Copy link
Member Author

I got this weird error recently.

Why is it weird? Can you please add a test covering that case?

Weird, become I never got it before and I didn't change something on my admin ^^'.

I tried to look at how to add a test, it's easy in master (and the check is already added https://github.com/sonata-project/SonataAdminBundle/blob/master/src/Admin/AbstractAdmin.php#L726) but in 3.x there is theoricaly a default value https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/AbstractAdmin.php#L184

@franmomu
Copy link
Member

Have you debug where the problem come from? A way to test it is in an Admin class create a method that overrides $datagridValues removing _per_page key.

@VincentLanglet
Copy link
Member Author

Have you debug where the problem come from? A way to test it is in an Admin class create a method that overrides $datagridValues removing _per_page key.

After debugging, there was no _per_page in the request because of some try (related to another PR and filters).

This test https://github.com/sonata-project/SonataAdminBundle/blob/master/tests/Admin/AdminTest.php#L1484 will check for this bug in master. I'm not sure about writing a new test on 3.x with a NEXT_MAJOR: Remove this test...

Copy link
Member

@franmomu franmomu left a comment

Choose a reason for hiding this comment

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

This test https://github.com/sonata-project/SonataAdminBundle/blob/master/tests/Admin/AdminTest.php#L1484 will check for this bug in master. I'm not sure about writing a new test on 3.x with a NEXT_MAJOR: Remove this test...

Hmm I think that test is testing it right now because this line:

// $defaultSortValues = ['_page' => 1, '_per_page' => 25];

is not resolved yet, once there are default values, is the same situation than now and that test will not longer cover this case.

Copy link
Member

@phansys phansys left a comment

Choose a reason for hiding this comment

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

IMO, we should add a test covering this case.

@VincentLanglet
Copy link
Member Author

I looked again and the function getDefaultSortValues will be final in 4.0 and always return a _per_page so the test won't be possible.

final protected function getDefaultSortValues(): array
{
    $defaultSortValues = ['_page' => 1, '_per_page' => 25];
}

@franmomu
Copy link
Member

I looked again and the function getDefaultSortValues will be final in 4.0 and always return a _per_page so the test won't be possible.

final protected function getDefaultSortValues(): array
{
    $defaultSortValues = ['_page' => 1, '_per_page' => 25];
}

You can use configureDefaultSortValues to override these values.

@VincentLanglet
Copy link
Member Author

I looked again and the function getDefaultSortValues will be final in 4.0 and always return a _per_page so the test won't be possible.

final protected function getDefaultSortValues(): array

{

$defaultSortValues = ['_page' => 1, '_per_page' => 25];

}

You can use configureDefaultSortValues to override these values.

I can override it, but it still will be set then.

@VincentLanglet VincentLanglet merged commit 3ed173b into 3.x Dec 23, 2020
@VincentLanglet VincentLanglet deleted the VincentLanglet-patch-2 branch December 23, 2020 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants