-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
REST API page size & current page search criteria options return item(s) past end of data set #8099
Comments
@careysizer thank you for your report. |
@veloraven - thanks, I've updated the issue to specify that CE is also affected (appears to be all versions of both editions that I've checked). I haven't reported this issue through the partner portal or other Magento channels. |
@misha-kotov please review MAGETWO-58841 before adding comment, this seems to be the same issue. |
The workaround we currently use is to check whether the last item on the previous page is identical to the last item on the current page. |
Verified and the internal issue is MAGETWO-58841 |
This appears a very substantial bug and there is still no resolution in the latest 2.1.7 version. Do you have estimate when you will fix this issue? |
@careys7, thank you for your report. |
The root of this problem seems to live in the file /**
* Get current collection page
*
* @param int $displacement
* @return int
*/
public function getCurPage($displacement = 0)
{
if ($this->_curPage + $displacement < 1) {
return 1;
} elseif ($this->_curPage + $displacement > $this->getLastPageNumber()) {
return $this->getLastPageNumber();
} else {
return $this->_curPage + $displacement;
}
} The upper-limit overflow can be addressed here, but the lower-limit overflow (page <= 0) is handled by /**
* Sets the limit and count by page number.
*
* @param int $page Limit results to this page number.
* @param int $rowCount Use this many rows per page.
* @return Zend_Db_Select This Zend_Db_Select object.
*/
public function limitPage($page, $rowCount)
{
$page = ($page > 0) ? $page : 1; //<---- This line right here
$rowCount = ($rowCount > 0) ? $rowCount : 1;
$this->_parts[self::LIMIT_COUNT] = (int) $rowCount;
$this->_parts[self::LIMIT_OFFSET] = (int) $rowCount * ($page - 1);
return $this;
} Lower-limit overflow is easy to detect (page <= 0), but upper-limit overflow is not. I have submitted a Pull Request at: #12475 |
From the issue description I see that API returns total amount of records: Could you please add more details why you need to access invalid page at all? It seems like there is some bug with last page determination in your code but why not fix invalid pagination instead of hacking core? |
It's certainly possible to calculate this. It's just a lot easier to keep asking for data until there's no more data. The bug is that the request returns incorrect data. If I request page 11 of 10, showing the results for page 10 is objectively wrong. Either an empty list. or a Bad Request or some such (given that we can calculate the max page, it would be a client error) would be correct. |
Well, such approach is buggy and should never be used as it simply does not work. "check whether the last item on the previous page is identical" is even more strange idea.
It just always fixes invalid page to first or last. It always worked like this since Magento 1 and there is nothing wrong with it.
This idea sounds good to me. It would be not OK to return some 500 HTTP error when you open invalid page in browser but looks pretty smooth for API. |
Why? There is absolutely nothing wrong with a loop that says "get data until there is no more data". This a basic pattern for manipulating arrays, queues, stacks, maps, sets, dictionaries, tuples, and loops. I can't think of a single instance of this statement being true that doesn't also involve some programming error that doesn't account for asynchronicity. |
@stevethedev because this criteria is not applicable here and thus causes bugs. You cannot take random algorithm, apply it to core, meet a bug and then try to "fix" core instead of fixing buggy algorithm. |
This is one of the most prolific algorithms in all of computing. Magento's API returns a result set that makes one of the most widely used algorithms ever created into an infinite loop. |
Vlad, I have worked with more than 50 different API services and I can assure you Steve is correct. This is how you work with paging APIs. This is a definite bug in the Magento API and you have to correct it and not ask clients to jump thru hoops to make it work. |
@nekobul, why you don't like the
approach? |
"It always worked like this since Magento 1 and there is nothing wrong with it." That statement is illogical. It worked like that, but it is inherently wrong to return something different from what you are requesting. I agree that, if it is inherited behavior, it's an improvement request and not a bug. Also, it would be a 4xx error, not 5xx error if you go that route. Frontend should handle errors on calls to backs, should not just show up, so I don't quite get that. As for desired behavior, I'm talking about the API, so a 400 error would probably be best. |
Vlad, No data returned is preferable because it will be easier to handle from the client side. |
Sorry, I didn't mean this will work like this forever, more thinking of "how many customizations will be broken if we change behavior consistently". @fvschie @nekobul if we fix it for Catalog pages as well, what would be the good behavior? Redirect to closest valid page or just show page with 0 products?
@nekobul well,
request seems pretty wrong to me. Client side has some error handling anyway, isn't it? And if by accident it requests invalid page, it will be more visible than if some products are returned, like it is currently. Looking at https://stackoverflow.com/a/3290198 I'm not sure whether 400 or 422 would be the best choice. |
Thank you for your submission. We recently made some changes to the way we process GitHub submissions to more quickly identify and respond to core code issues. Feature Requests and Improvements should now be submitted to the new Magento 2 Feature Requests and Improvements forum (see details here). We are closing this GitHub ticket and have moved your request to the new forum. |
@piotrekkaminski is this a feature? |
Had the same problem, changed my client... |
@okorshenko, could you please share a status of MAGETWO-58841 ticket (in progress, closed, etc)? Thank you! CC: @dmytro-ch |
Hello @atwixfirster @amenk @careys7 @dmytro-ch I just checked the internal Jira ticket I see it has a huge amount of records/actions since it was created in 2016 Last comments from engineering were in March-April of 2019 and it is about At this moment |
Hello @sdzhepa, thank you for the details! |
FYI we have #26988 that should solve this issue. |
You can buy me a beer at the next conference @careys7 :-D |
Preconditions
Steps to reproduce
This issue appears to affect at least /products/ and /categories/ requests. I have added below an example for products.
Note: Page size of '1' above is a nominal value to make examples given below more concise.
Expected result
Actual result
The text was updated successfully, but these errors were encountered: