Tigrov / yii2-pgsql

Improved PostgreSQL schemas for Yii2
MIT License
34 stars 6 forks source link

Bug when using together with yii2-queue #6

Closed ekzobrain closed 7 years ago

ekzobrain commented 7 years ago

Hi.

When using your extension together with yii2-queue - it breaks because it uses bit field in an old manner (asumes PHP type to be an integer). I very much need your extension for Array and JSON fields, but other type conversions often make mess with other extensions and standard framework functionality. Could you, please, make a separate Shema class which would only handle Array and JSON types, and leave other's behavior untouched?

ekzobrain commented 7 years ago

composite and domain types could also be included, because theese types are new and they won't break anything.

Tigrov commented 7 years ago

Hi,

Could you explain which exactly field in the extension yii2-queue has incompatibility? Maybe some code to inproduce the error.

Now I see that yii2-queue has a binary type field job
https://github.com/yiisoft/yii2-queue/blob/master/src/drivers/db/migrations/M161119140200Queue.php#L27

and the base class \yii\db\pgsqlQueryBuilder has an array construction as a value for binary types $columns[$name] = [$value, \PDO::PARAM_LOB];
https://github.com/yiisoft/yii2/blob/master/framework/db/pgsql/QueryBuilder.php#L276

Is this the reason or something else?

ekzobrain commented 7 years ago

I got this error when enabled your extension:

2017-10-08 18:16:11 [-][-][-][error][yii\queue\Queue] [33274] app\tasks\NotifyMissed (attempt: 1) error PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type bytea in /var/www/vpbx/vendor/yiisoft/yii2/db/Command.php:842
Stack trace:
#0 /var/www/vpbx/vendor/yiisoft/yii2/db/Command.php(842): PDOStatement->execute()
#1 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/drivers/db/Queue.php(107): yii\db\Command->execute()
#2 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/Queue.php(146): yii\queue\db\Queue->pushMessage('O:22:"app\\tasks...', 30, 600, NULL)
#3 /var/www/vpbx/tasks/NotifyMissed.php(69): yii\queue\Queue->push(Object(app\tasks\NotifyMissed))
#4 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/Queue.php(190): app\tasks\NotifyMissed->execute(Object(yii\queue\db\Queue))
#5 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/cli/Queue.php(87): yii\queue\Queue->handleMessage('33274', 'O:22:"app\\tasks...', '30', '1')
#6 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/cli/Command.php(112): yii\queue\cli\Queue->execute('33274', 'O:22:"app\\tasks...', '30', '1')
#7 [internal function]: yii\queue\cli\Command->actionExec('33274', '30', '1')
#8 /var/www/vpbx/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /var/www/vpbx/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#10 /var/www/vpbx/vendor/yiisoft/yii2/console/Controller.php(128): yii\base\Controller->runAction('exec', Array)
#11 /var/www/vpbx/vendor/yiisoft/yii2/base/Module.php(523): yii\console\Controller->runAction('exec', Array)
#12 /var/www/vpbx/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)
#13 /var/www/vpbx/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('queue/exec', Array)
#14 /var/www/vpbx/vendor/yiisoft/yii2/base/Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#15 /var/www/vpbx/yii(20): yii\base\Application->run()
#16 {main}

Next yii\db\Exception: SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type bytea
The SQL being executed was: INSERT INTO "queue" ("channel", "job", "pushed_at", "ttr", "delay", "priority") VALUES ('queue', 'O:22:"app\tasks\NotifyMissed":4:{s:9:"domain_id";i:3;s:8:"interval";i:600;s:4:"from";O:8:"DateTime":3:{s:4:"date";s:26:"2017-10-08 18:16:11.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}s:3:"uid";s:13:"59b7869c0f9f9";}', 1507486571, 30, 600, 1024) in /var/www/vpbx/vendor/yiisoft/yii2/db/Schema.php:636
Stack trace:
#0 /var/www/vpbx/vendor/yiisoft/yii2/db/Command.php(852): yii\db\Schema->convertException(Object(PDOException), 'INSERT INTO "qu...')
#1 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/drivers/db/Queue.php(107): yii\db\Command->execute()
#2 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/Queue.php(146): yii\queue\db\Queue->pushMessage('O:22:"app\\tasks...', 30, 600, NULL)
#3 /var/www/vpbx/tasks/NotifyMissed.php(69): yii\queue\Queue->push(Object(app\tasks\NotifyMissed))
#4 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/Queue.php(190): app\tasks\NotifyMissed->execute(Object(yii\queue\db\Queue))
#5 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/cli/Queue.php(87): yii\queue\Queue->handleMessage('33274', 'O:22:"app\\tasks...', '30', '1')
#6 /var/www/vpbx/vendor/yiisoft/yii2-queue/src/cli/Command.php(112): yii\queue\cli\Queue->execute('33274', 'O:22:"app\\tasks...', '30', '1')
#7 [internal function]: yii\queue\cli\Command->actionExec('33274', '30', '1')
#8 /var/www/vpbx/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /var/www/vpbx/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#10 /var/www/vpbx/vendor/yiisoft/yii2/console/Controller.php(128): yii\base\Controller->runAction('exec', Array)
#11 /var/www/vpbx/vendor/yiisoft/yii2/base/Module.php(523): yii\console\Controller->runAction('exec', Array)
#12 /var/www/vpbx/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)
#13 /var/www/vpbx/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('queue/exec', Array)
#14 /var/www/vpbx/vendor/yiisoft/yii2/base/Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#15 /var/www/vpbx/yii(20): yii\base\Application->run()
#16 {main}
Additional Information:
Array
(
    [0] => 22P02
    [1] => 7
    [2] => ERROR:  invalid input syntax for type bytea
)
Tigrov commented 7 years ago

Ok, this is related to the binary type, not the bit type.

Try the last fix. Be sure that you are trying the dev version, e.g. "tigrov/yii2-pgsql": "dev-master" in your composer.json

If everything fine, I release it.

ekzobrain commented 7 years ago

It seems to be OK now, thanks.