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

Odd condition builder problem in only console application #17090

Closed
fonemi opened this issue Jan 31, 2019 · 8 comments
Closed

Odd condition builder problem in only console application #17090

fonemi opened this issue Jan 31, 2019 · 8 comments
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@fonemi
Copy link

fonemi commented Jan 31, 2019

What steps will reproduce the problem?

I have an account settings table which stores key-value paired settings for accounts. It has 3 columns: account_ID, key, value and its primary key is composite (account_ID, key).
I use a db schema cache.
When I try to read account settings, as follows:

public function getAccountSettings()
	{
		return $this->hasMany(AccountSetting::className(), ['account_ID' => 'ID'])->inverseOf('account');
	}

public function getSetting($key, $default = null) {
    	$retval = $this->getAccountSettings()->select(['value'])->where(['key' => $key])->scalar();
    	if($retval !== false) return $retval;
    	return $default;
    }

, it works as a charm in my dev server (both web and console). In prod server, it works as well in a web controller, however the same call gives an error in a console controller which I call by a shell command.

I don't understand why a console controller in the prod server differs. It's an odd behavior.

Dev server uses MySQL while prod server uses MariaDb. But it still doesn't explain the difference between the web and the console controllers.

Extra note: In SimpleConditionBuilder, getColumn() from ExpressionInterface is put as a parameter to strpos, but getColumn() seems to return mixed, not string.

What is the expected result?

I expect console application works like web application and gives no error.

What do you get instead?

PHP Warning 'yii\base\ErrorException' with message 'strpos() expects parameter 1 to be string, array given'

in /home/carbon/public_html/vendor/yiisoft/yii2/db/conditions/SimpleConditionBuilder.php:40

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'strpos() expect...', '/home/carbon/pu...', 40, Array)
#1 /home/carbon/public_html/vendor/yiisoft/yii2/db/conditions/SimpleConditionBuilder.php(40): strpos(Array, '(')
#2 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(283): yii\db\conditions\SimpleConditionBuilder->build(Object(yii\db\conditions\SimpleCondition), Array)
#3 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(1527): yii\db\QueryBuilder->buildExpression(Object(yii\db\conditions\SimpleCondition), Array)
#4 /home/carbon/public_html/vendor/yiisoft/yii2/db/conditions/ConjunctionConditionBuilder.php(60): yii\db\QueryBuilder->buildCondition(Object(yii\db\conditions\SimpleCondition), Array)
#5 /home/carbon/public_html/vendor/yiisoft/yii2/db/conditions/ConjunctionConditionBuilder.php(35): yii\db\conditions\ConjunctionConditionBuilder->buildExpressionsFrom(Array, Array)
#6 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(283): yii\db\conditions\ConjunctionConditionBuilder->build(Object(yii\db\conditions\AndCondition), Array)
#7 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(1527): yii\db\QueryBuilder->buildExpression(Object(yii\db\conditions\AndCondition), Array)
#8 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(1336): yii\db\QueryBuilder->buildCondition(Object(yii\db\conditions\AndCondition), Array)
#9 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(235): yii\db\QueryBuilder->buildWhere(Array, Array)
#10 /home/carbon/public_html/vendor/yiisoft/yii2/db/ActiveQuery.php(316): yii\db\QueryBuilder->build(Object(yii\db\Query))
#11 /home/carbon/public_html/vendor/yiisoft/yii2/db/Query.php(291): yii\db\ActiveQuery->createCommand(Object(yii\db\Connection))
#12 /home/carbon/public_html/models/Account.php(139): yii\db\Query->scalar()
#13 /home/carbon/public_html/models/forms/Account.php(128): app\models\Account->getSetting('billing_company...')

Additional info

Q A
Yii version 2.0.15.1
Prod PHP version 7.1.26
Prod Operating system Centos 7.4.1708
Prod MySQL version 15.1 Distrib 5.5.60-MariaDB
Dev PHP version 7.1.25
Dev Operating system MacOS 10.14.2
Dev MySQL version 8.0.13
@samdark
Copy link
Member

samdark commented Feb 1, 2019

Would you please try 2.0.16?

@yiisoft yiisoft deleted a comment from yii-bot Feb 1, 2019
@fonemi
Copy link
Author

fonemi commented Feb 1, 2019

I've just tried. Same behavior in 2.0.16.

@samdark samdark added this to the 2.0.17 milestone Feb 2, 2019
@samdark samdark added the status:to be verified Needs to be reproduced and validated. label Feb 2, 2019
@fonemi
Copy link
Author

fonemi commented Feb 2, 2019

When I trace the returned array from getColumn(), it's a 1-element array:
[0 => 'account_ID']

@samdark
Copy link
Member

samdark commented Feb 3, 2019

That's weird. Is it reproduceable with starting clean with basic application template?

@fonemi
Copy link
Author

fonemi commented Feb 7, 2019

I will try it but I have looked at the prod server's bash configuration since the problem only occurs in prod console commands. I think something goes wrong with locale/encoding/line endings.

  1. In the beginning, ./yii command itself was giving "no such file or directory" error. I hadn't done any changes on ./yii file in the basic application template before I entered :set fileformat=unix in vi editor and it started working.

  2. I've just noticed ./yii has problems with the letter "i" in the commands.
    ./yii help/index gives:

Unknown command: help/index
Did you mean "help/index"?

./yii help also does not recognize command:

Unknown command: help

Did you mean one of these?
- help
- help/index
- help/list
- help/list-action-options
- help/usage

./yii help/usage help/usage works properly. ./yii cache/flush works while ./yii cache/index does not.

Maybe it is a related situation with the main problem. The "i" letter also exists in "account_ID".

Some locale outputs from my console:

$ locale charmap
UTF-8
$ echo $LC_ALL
tr_TR.UTF-8
$ echo $LANG
tr_TR.UTF-8

@samdark
Copy link
Member

samdark commented Feb 7, 2019

That is still sounds too weird to reproduce. Unfortunately we can't fix it if it's not reproducible.

@samdark samdark closed this as completed Mar 20, 2019
@udokmeci
Copy link

I will try it but I have looked at the prod server's bash configuration since the problem only occurs in prod console commands. I think something goes wrong with locale/encoding/line endings.

  1. In the beginning, ./yii command itself was giving "no such file or directory" error. I hadn't done any changes on ./yii file in the basic application template before I entered :set fileformat=unix in vi editor and it started working.
  2. I've just noticed ./yii has problems with the letter "i" in the commands.
    ./yii help/index gives:

Unknown command: help/index
Did you mean "help/index"?

./yii help also does not recognize command:

Unknown command: help
Did you mean one of these?

  • help
  • help/index
  • help/list
  • help/list-action-options
  • help/usage

./yii help/usage help/usage works properly. ./yii cache/flush works while ./yii cache/index does not.

Maybe it is a related situation with the main problem. The "i" letter also exists in "account_ID".

Some locale outputs from my console:

$ locale charmap
UTF-8
$ echo $LC_ALL
tr_TR.UTF-8
$ echo $LANG
tr_TR.UTF-8

Hi,
I could reproduce issue exactly on web also. Problem is related to Turkish Locale and only produced on PHP 7.2.18 on centos 7. Changing locale to English solves the problem but formatter does not seems to work with locale also.

Regards

@samdark samdark removed this from the 2.0.17 milestone May 28, 2019
@samdark samdark reopened this May 28, 2019
@udokmeci
Copy link

Hi again this is not related to the yii2. this bug is propably from php itself. So you can close it.
Probably related bug is here https://bugs.php.net/bug.php?id=18556
Regards

@samdark samdark closed this as completed May 30, 2019
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. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants