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

[3.1.0] Issue with doLowUpdate() - First argument is not array #12742

Closed
virgofx opened this issue Mar 23, 2017 · 5 comments
Closed

[3.1.0] Issue with doLowUpdate() - First argument is not array #12742

virgofx opened this issue Mar 23, 2017 · 5 comments
Milestone

Comments

@virgofx
Copy link
Contributor

virgofx commented Mar 23, 2017

$robot = Robots::findFirst();

$robot2 = new Robot($robot->toArray(), $di, $modelsManager);
$robot2->setNewValueForField(100);

try {
    $robot2->setDirtyState($robot2::DIRTY_STATE_PERSISTENT); 
    $robot2->save();
} catch (\Exception $exception) {
   echo "ERROR: " . $exception->getMessage();
}

Results in:
ERROR: First argument is not an array

@sergeyklay sergeyklay added this to the 3.1.1 milestone Mar 23, 2017
@sergeyklay
Copy link
Contributor

Fixed in the 3.1.x branch. Thank you

@Fishdrowned
Copy link
Contributor

Fishdrowned commented Mar 24, 2017

@sergeyklay I think it would be necessary to release a hotfix version (like 3.1.0-1) immediately, because this is really a serious bug.

@Jurigag
Copy link
Contributor

Jurigag commented Mar 24, 2017

Not really a serious bug, it only happens in one case - if in new Robots you will set primary key by yourself and it will exists in database, like in this case from this issue, and most of the time you shouldn't do it like this anyway, otherwise there is no this error.

You can always use zephir and compile and have it fixed immediately.

Though i guess it's not problem to release version like you mention and recreate build right now, i guess in some apps to not have additional query for select you could use it perhaps.

@Fishdrowned
Copy link
Contributor

@Jurigag No, it may occur even with a new primary key, if you save the model and then save it again.

Let's take a k-v table as a example:

<?php

use Phalcon\Mvc\Model;
use Phalcon\Db\Adapter\Pdo\Mysql as PhalconMysql;

class TestPhalconSnapshot extends Model
{
    public $key;
    public $value;

    public function initialize()
    {
        $this->setSource('test_snapshot');
        $this->keepSnapshots(true);
    }
}

$di = new Phalcon\Di\FactoryDefault;
$di->set('db', function () {
    return new PhalconMysql([
        'host' => 'localhost',
        'username' => 'root',
        'password' => '',
        'dbname' => 'phalcon_test',
    ]);
});

/* @var PhalconMysql $db */
$db = $di->getShared('db');

$db->execute('CREATE TABLE IF NOT EXISTS `test_snapshot` (
 `key` VARCHAR(32) COLLATE utf8_unicode_ci NOT NULL,
 `value` TEXT COLLATE utf8_unicode_ci,
 PRIMARY KEY (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');

Model::setup([
    'exceptionOnFailedSave' => true,
]);

$model = new TestPhalconSnapshot;
$model->key = microtime();
$model->value = '';
$model->save(); // OK here
$model->value = time();
$model->save(); // Error

Result:

christopher@Christopher-Macmini:/var/www/test/php/phalcon/3.1.0$ php --ri phalcon|grep Ver
Version => 3.1.0
Powered by Zephir => Version 0.9.6a-dev-1bad5e7742

christopher@Christopher-Macmini:/var/www/test/php/phalcon/3.1.0$ php model.snapshot.bug.php 
PHP Warning:  First argument is not an array in /var/www/test/php/phalcon/3.1.0/model.snapshot.bug.php on line 46
PHP Stack trace:
PHP   1. {main}() /var/www/test/php/phalcon/3.1.0/model.snapshot.bug.php:0
PHP   2. Phalcon\Mvc\Model->save() /var/www/test/php/phalcon/3.1.0/model.snapshot.bug.php:46
PHP   3. Phalcon\Mvc\Model->_doLowUpdate() /var/www/test/php/phalcon/3.1.0/model.snapshot.bug.php:46

@Jurigag
Copy link
Contributor

Jurigag commented Mar 24, 2017

use Phalcon\Db;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Model;

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Model::setup(['castOnHydrate' => true]);

$di = new FactoryDefault();
$di->set(
    'db',
    function () {
        $adapter = new \Phalcon\Db\Adapter\Pdo\Mysql(
            [
                'host'     => 'localhost',
                'username' => 'root',
                'password' => '',
                'dbname'   => 'phalcon_test',
                'options'  => [
                    PDO::ATTR_EMULATE_PREPARES   => false,
                    PDO::ATTR_STRINGIFY_FETCHES  => false,
                    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
                ],
                'charset'  => 'utf8',
            ]
        );

        return $adapter;
    }
);

class Robots extends \Phalcon\Mvc\Model
{
    public function initialize()
    {
        $this->keepSnapshots(true);
    }
}

$robot = new Robots();
$robot->name = "asd";
$robot->type = "mechanical";
$robot->text = "text";
$robot->datetime = "1952-01-01 00:00:00";
$robot->save();
$robot->name = "asds";
$robot->save();

don't have a warning, you sure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants