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

Infinite query loop "ActiveDataProvider" when the index does not exist #134

Closed
unasoft opened this issue Jun 28, 2017 · 2 comments
Closed

Comments

@unasoft
Copy link

unasoft commented Jun 28, 2017

What steps will reproduce the problem?

When the index does not exist and we refer to it, we get false because the expected array is trying to get data again and so infinitely

    public function getQueryResults()
    {
        if (!is_array($this->_queryResults)) {
            $this->prepare();
        }
        return $this->_queryResults;
    }

PS: Sorry for my english

Additional info

Q A
Yii vesion n/a
PHP version n/a
Operating system n/a
@yii-bot
Copy link

yii-bot commented Jun 28, 2017

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

@seesoft-dev
Copy link

seesoft-dev commented Jun 28, 2017

code exemple:

$provider = new ActiveDataProvider([
      'query' => Entry::find(),
      'pagination' => [
      'pageSize' => 10,
  ]
]);

return $this->render('index', ['models' => $provider->getModels()]);

if the index doesn't exist, the page hangs up because "getQueryResult" expects array but $results = $query->search($this->db); false returns and prepare in a cycle is launched

   public function getQueryResults()
    {
        if (!is_array($this->_queryResults)) {
            $this->prepare();
        }
        return $this->_queryResults;
    }

@cebe cebe added this to the 2.0.5 milestone Jul 3, 2017
samdark added a commit that referenced this issue May 1, 2019
* 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
tunecino added a commit to tunecino/yii2-elasticsearch that referenced this issue Jun 23, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants