yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.9k forks source link

BC break: \yii\data\ActiveDataProvider throws yii\base\InvalidConfigException depending on array config keys order #20221

Closed MarkoNV closed 4 months ago

MarkoNV commented 4 months ago

What steps will reproduce the problem?

At any instance of \yii\data\ActiveDataProvider swap pagination and query in array.

Example: Change from: $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSizeLimit' => false, 'defaultPageSize' => 6, 'forcePageParam' => false, ], ]); to: $dataProvider = new ActiveDataProvider([ 'pagination' => [ 'pageSizeLimit' => false, 'defaultPageSize' => 6, 'forcePageParam' => false, ], 'query' => $query, ]);

What is the expected result?

Order of array keys doesn't matter, as if was in < 2.0.50

What do you get instead?

Invalid Configuration – yii\base\InvalidConfigException The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses. in .../vendor/yiisoft/yii2/data/ActiveDataProvider.php at line 164

Additional info

Looks like prepareTotalCount() is called from setPaginator. In older versions that wasn't case and fact that setPagination is called from Yii::configure() before query is set didn't cause problem.

Q A
Yii version 2.0.50
PHP version any
Operating system any
samdark commented 4 months ago

Should be already fixed in master.