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

sometime my code run well, but sometime this error occurs #5797

Closed
hehbhehb opened this issue Oct 29, 2014 · 12 comments
Closed

sometime my code run well, but sometime this error occurs #5797

hehbhehb opened this issue Oct 29, 2014 · 12 comments
Assignees
Labels
status:to be verified Needs to be reproduced and validated.

Comments

@hehbhehb
Copy link

2014-10-29 14:15:35 [111.172.8.83][][-][error][yii\base\ErrorException:8] exception 'yii\base\ErrorException' with message 'Trying to get property of non-object' in /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveRecord.php:359
Stack trace:
#0 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveRecord.php(359): yii\base\ErrorHandler->handleError(8, 'Trying to get p...', '/mnt/wwwroot/wx...', 359, Array)
#1 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveQueryTrait.php(132): yii\db\ActiveRecord::populateRecord(Object(app\models\MItem), Array)
#2 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveQuery.php(218): yii\db\ActiveQuery->createModels(Array)
#3 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/Query.php(207): yii\db\ActiveQuery->populate(Array)
#4 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveQuery.php(130): yii\db\Query->all(NULL)
#5 /mnt/wwwroot/wx/controllers/WapController.php(1143): yii\db\ActiveQuery->all()
#6 [internal function]: app\controllers\WapController->actionCardlist()
#7 /mnt/wwwroot/wx/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#8 /mnt/wwwroot/wx/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#9 /mnt/wwwroot/wx/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('cardlist', Array)
#10 /mnt/wwwroot/wx/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction('wap/cardlist', Array)
#11 /mnt/wwwroot/wx/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 /mnt/wwwroot/wx/web/index.php(14): yii\base\Application->run()
#13 {main}

Yii is 2.0.0

@hehbhehb
Copy link
Author

code fragments:
public function actionCardlist()
{
....
$this->layout ='wapy';
$models = MItem::find()->where(['kind'=>$kind])->orderBy(['price'=>SORT_DESC])->all();
....
}

@mitalcoi
Copy link
Contributor

How many records you have in table associated with MItem?

@hehbhehb
Copy link
Author

3 records

@mdmunir
Copy link
Contributor

mdmunir commented Oct 29, 2014

show your MItem class.

@qiangxue
Copy link
Member

Please show the PHP type of the value of MItem::getTableSchema(). What is your database type? Did you enable schema caching?

@hehbhehb
Copy link
Author

it is object, mysql, yes, I enabled schema caching

2014-10-31 09:08:52,yii\db\TableSchema Object
(
[schemaName] =>
[name] => wx_item
[fullName] => wx_item
[primaryKey] => Array
(
[0] => iid
)

[sequenceName] =>
[foreignKeys] => Array
    (
    )

[columns] => Array
    (
        [iid] => yii\db\ColumnSchema Object
            (
                [name] => iid
                [allowNull] =>
                [type] => integer
                [phpType] => integer
                [dbType] => int(10) unsigned
                [defaultValue] =>
                [enumValues] =>
                [size] => 10
                [precision] => 10
                [scale] =>
                [isPrimaryKey] => 1
                [autoIncrement] => 1
                [unsigned] => 1
                [comment] =>
            )

        [gh_id] => yii\db\ColumnSchema Object
            (
                [name] => gh_id
                [allowNull] =>
        ....

....
)

CREATE TABLE wx_item (
iid int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
gh_id VARCHAR(32) NOT NULL DEFAULT '',
price int(10) unsigned NOT NULL DEFAULT '0',
price_hint VARCHAR(128) NOT NULL DEFAULT '',
title VARCHAR(128) NOT NULL DEFAULT '',
title_hint VARCHAR(256) NOT NULL DEFAULT '',
pkg_name VARCHAR(128) NOT NULL DEFAULT '',
pkg_name_hint VARCHAR(256) NOT NULL DEFAULT '',
detail text NOT NULL DEFAULT '',
pic_url VARCHAR(256) NOT NULL DEFAULT '',
cid int(10) unsigned NOT NULL DEFAULT '0',
status int(10) unsigned NOT NULL DEFAULT '0',
quantity int(10) unsigned NOT NULL DEFAULT '0',
old_price int(10) unsigned NOT NULL DEFAULT '0',
old_price_hint VARCHAR(128) NOT NULL DEFAULT '',
ctrl_soldout tinyint(3) unsigned NOT NULL DEFAULT '0',
KEY gh_id_idx(gh_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

config/db.php:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=wx',
'username' => 'xxx',
'password' => 'xxx',
'charset' => 'utf8',
'enableSchemaCache' => true,
'schemaCacheDuration' => YII_DEBUG ? 10 : 3600,
];

web.php
...
'cache' => [
'class' => 'yii\caching\MemCache',
'keyPrefix' => 'ya54dee8',
'servers' => [
[
'host' => 'localhost',
'port' => 11211,
'weight' => 100,
],
],
],
...

@qiangxue
Copy link
Member

Please replace line 359 in yii\db\ActiveRecord with the following code and show the exception message when it happens:

$schema = static::getTableSchema();
if (!$schema instanceof TableSchema) {
    throw new Exception("Unexpected type: " . gettype($schema));
}
$columns = $schema->columns;

@hehbhehb
Copy link
Author

type is string

2014-10-31 13:19:34 [171.82.160.72][][-][error][yii\db\Exception] exception 'yii\db\Exception' with message 'Unexpected type: string' in /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveRecord.php:370
Stack trace:
#0 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveQueryTrait.php(132): yii\db\ActiveRecord::populateRecord(Object(app\models\MUser), Array)
#1 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveQuery.php(218): yii\db\ActiveQuery->createModels(Array)
#2 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveQuery.php(287): yii\db\ActiveQuery->populate(Array)
#3 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/ActiveRecord.php(180): yii\db\ActiveQuery->one()
#4 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/BaseActiveRecord.php(101): yii\db\ActiveRecord::findByCondition(Array, true)
#5 /mnt/wwwroot/wx/controllers/WapController.php(499): yii\db\BaseActiveRecord::findOne(Array)
#6 [internal function]: app\controllers\WapController->actionG2048()
#7 /mnt/wwwroot/wx/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#8 /mnt/wwwroot/wx/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#9 /mnt/wwwroot/wx/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('g2048', Array)
#10 /mnt/wwwroot/wx/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction('wap/g2048', Array)
#11 /mnt/wwwroot/wx/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 /mnt/wwwroot/wx/web/index.php(14): yii\base\Application->run()
#13 {main}

@qiangxue
Copy link
Member

What is the value of $schema when it is a string? It seems your memcache may have some problem.

@hehbhehb
Copy link
Author

hehbhehb commented Nov 6, 2014

it is string type, and its value is some number, such as "0.83963800 1415176883". yes, i will check my memcached

@hehbhehb
Copy link
Author

hehbhehb commented Nov 7, 2014

i replace the memcache with apc, and got new errors
2014-11-07 13:17:19 [-][-][-][error][yii\base\ErrorException:2] exception 'yii\base\ErrorException' with message 'array_keys() expects parameter 1 to be array, boolean given' in /mnt/wwwroot/wx/vendor/yiisoft/yii2/caching/ApcCache.php:83
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'array_keys() ex...', '/mnt/wwwroot/wx...', 83, Array)
#1 /mnt/wwwroot/wx/vendor/yiisoft/yii2/caching/ApcCache.php(83): array_keys(false)
#2 /mnt/wwwroot/wx/vendor/yiisoft/yii2/caching/Cache.php(235): yii\caching\ApcCache->setValues(Array, 0)
#3 /mnt/wwwroot/wx/vendor/yiisoft/yii2/caching/TagDependency.php(87): yii\caching\Cache->mset(Array)
#4 /mnt/wwwroot/wx/vendor/yiisoft/yii2/caching/TagDependency.php(43): yii\caching\TagDependency::touchKeys(Object(yii\caching\ApcCache), Array)
#5 /mnt/wwwroot/wx/vendor/yiisoft/yii2/caching/Dependency.php(54): yii\caching\TagDependency->generateDependencyData(Object(yii\caching\ApcCache))
#6 /mnt/wwwroot/wx/vendor/yiisoft/yii2/caching/Cache.php(193): yii\caching\Dependency->evaluateDependency(Object(yii\caching\ApcCache))
#7 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/Schema.php(129): yii\caching\Cache->set(Array, Object(yii\db\TableSchema), 3600, Object(yii\caching\TagDependency))
#8 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/Connection.php(709): yii\db\Schema->getTableSchema('wx_order', false)
#9 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/QueryBuilder.php(236): yii\db\Connection->getTableSchema('wx_order')
#10 /mnt/wwwroot/wx/vendor/yiisoft/yii2/db/Command.php(470): yii\db\QueryBuilder->update('wx_order', Array, 'status=:status ...', Array)

@samdark samdark added the status:to be verified Needs to be reproduced and validated. label Nov 7, 2014
@qiangxue
Copy link
Member

qiangxue commented Nov 7, 2014

The APC issue was already fixed in master.
The original schema issue was also fixed in a separate commit.

@qiangxue qiangxue closed this as completed Nov 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated.
Projects
None yet
Development

No branches or pull requests

5 participants