-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
Maximum function nesting level of '256' reached, aborting! in /vendor/yiisoft/yii2-elasticsearch/ActiveDataProvider.php:82 #201
Comments
... |
What code do you call to have this error? |
In SearchModel on call getModels method: $query = new yii\elasticsearch\Query(); |
What's in the query? |
{"size":50,"query":{"constant_score":{"filter":{"bool":{"must":[{"range":{"reg_date":{"gte":"2019-01-16T00:00:00+03:00"}}},{"range":{"reg_date":{"lte":"2019-01-16T23:59:59+03:00"}}}]}}}},"sort":[{"reg_date":"desc"}]} |
I can't reproduce the problem.
SiteController.php
And in
Everything works fine! Pagination, total row amount, sorting and so on. Do I misunderstood something? |
Aha, I think "yiisoft/yii2-elasticsearch ~2.1" matters. |
What version is right for |
2.1.x |
didn't help |
@GHopperMSK have you checked with 2.1 branch? |
Depend on minimum stability |
Change description and steps for reproduce |
It doesn't depend on Here is infinity loop in
We have to rethink yiisoft/yii2#16951! Specifically: if (($this->_pagination !== false) && ($this->_pagination->totalCount === null)) {
if ($this->_totalCount === null) {
$this->setTotalCount($this->prepareTotalCount());
}
$this->_pagination->totalCount = $this->_totalCount;
} |
Change |
Let`s look at yii2-elasticsearch/ActiveDataProvider.php Lines 82 to 107 in 0c2fa9f
First we call protected function prepareModels1()
{
if (!$this->query instanceof Query) {
throw new InvalidConfigException('The "query" property must be an instance "' . Query::className() . '" or its subclasses.');
}
$query = clone $this->query;
$results = $query->search($this->db);
$this->setQueryResults($results);
if (($pagination = $this->getPagination()) !== false) {
// pagination fails to validate page number, because total count is unknown at this stage
$pagination->validatePage = false;
$query->limit($pagination->getLimit())->offset($pagination->getOffset());
}
if (($sort = $this->getSort()) !== false) {
$query->addOrderBy($sort->getOrders());
}
if ($pagination !== false) {
$pagination->totalCount = $this->getTotalCount();
}
return $results['hits']['hits'];
} It works, but I didn't run tests yet. |
|
I don't think this is an efficient solution, query will be executed twice. And the method will fetch "all records" at the first query. |
The solution doesn't add any queries, it just rearrange them. But in general I agree with you. There are many places have to be refactored. |
I' sorry, I overlooked your code. There is no second query. |
Please apply this fix for 2.1.x-dev |
Hi guys, PR #204 introduced regression that's breaking sorting and pagination in data provider. It is because query is now executed before pagination and sort methods are applied, so they have no effect at all. |
@GHopperMSK any other idea about fixing it? |
I have a few ideas, but it will take some time. |
Would these require changes in framework itself? Asking because we'd like to tag 2.0.16 before end of the month. |
I don't think so. But as you know, it is quite unpredictable ) |
The current solution isn't optimal due to it makes redundant request for obtain totalCount. For solving this situation I need |
In general, it solved. You are welcome for checking. |
Seems to be affecting yii2-sphinx as well: https://travis-ci.org/yiisoft/yii2-sphinx/jobs/495100578 |
Yii 2 change reverted. I'll clean up commits to ES as well. |
* Update Query.php (#131) * PHPUnit compatibility, provide token for github auth * token update * yet another update * Fix #134 infinite query loop when the index does not exist * improved error message for cluster auto detection issue #137 * updated docs about cluster autodetection fixes #137 * Elasticsearch logo added to README.md * Composer json change * Added alias actions to Command * Fix for desirialization of plain response from elasticsearch * Bring back old name for package * Fix for php 5.4 * Added phpdocs, fixes and tests * CHANGELOG.md * clarify version compatibility * Fixing broken elasticsearch doc links (#144) [skip ci] * Fixes #149: Changed `yii\base\Object` to `yii\base\BaseObject` * since elasticsearch 6, content type is mandatory (#150) since elasticsearch 6, content type is mandatory. Otherwise, requests will all fail. https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests * added CHANGELOG for #150 * Reset query results after calling refresh() method close #125 * Fixes case (#153) [skip ci] * Fix spelling (#165) [skip ci] * fix findAll and findOne to filter input to avoid passing manipulated condition * release version 2.0.5 * prepare for next release * Update README.md * docs/guide-ja updated [ci skip] (#178) * Removed redundant line from license [skip ci] * guide-ja revised [ci skip] * Fixed `count()` compatibility with PHP 7.2 do not call it on scalar values. fixes #180 * Translate into Russian (#194) [skip ci] * Improve Russian docs (#200) [skip ci] * Bug #201: Fixed infinite loop * Updated issue template [skip ci] * Made tests running again (#210) * Revert "Bug #201: Fixed infinite loop" This reverts commit aa22ffd. * Fixes #218: Comment out invalid syntax in sample [skip ci] (#219) * docs/guide-ja/mapping-indexing.md updated [ci skip] (#221) * Fixes #227: Fixed `Bad Request (#400): Unable to verify your data submission.` in debug details panel 'run query' * Travis adjustments (#228) * Use assertCount() in tests * Add missing relations to Order test model * Add note delete-by-query plugin (#158) * Fixes #117: Add support for `QueryInterface::emulateExecution()` * Specified versions that work
related to yiisoft#134 and yiisoft#201. There is currently an infinite loop that happens when following method is called before getting any results from ElasticSearch: ``` prepareModels() ->getPagination() ->prepareTotalCount() ->getQueryResults() ->prepare() ->prepareModels() ``` It seems the infinite loop issue has already been fixed at some point, but then reverted by yiisoft@58466a8. This PR tries a different fix to the same issue by simply ensuring `prepareTotalCount()` to request the number from the database in case we have no available query response, the exact same way it was done with core `ActiveDataProvider::prepareTotalCount()` for SQL databases, Mongo and Sphinx extensions.
On "minimum-stability": stable work fine !
Infinite loop after Yii2 update:
yiisoft/yii2@a5182e5
What steps will reproduce the problem?
"minimum-stability": stable --> dev,
"php": >=5.4.0 --> >=7.0
"require": add "yiisoft/yii2-elasticsearch": "~2.1"
Finaly composer.json
What's expected?
\yii\elasticsearch\ActiveDataProvide::getModels() return array
What do you get instead?
Additional info
The text was updated successfully, but these errors were encountered: