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

[BUG]: Model setters do not call during hydration #14810

Open
jaguarsdv opened this issue Feb 4, 2020 · 4 comments
Open

[BUG]: Model setters do not call during hydration #14810

jaguarsdv opened this issue Feb 4, 2020 · 4 comments
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Comments

@jaguarsdv
Copy link

jaguarsdv commented Feb 4, 2020

Questions? Forum: https://phalcon.link/forum or Discord: https://phalcon.link/discord

Describe the bug
During hydration using Resultset::HYDRATE_RECORDS mode Models protected/private property values sets like they are public ones instead to be set using setters.

To Reproduce
Generate any model that uses setters and getters. At setters throw any kind of exception. Retrieving record by calling Model::findFirst() expected that exception will be thown in setters. But there is no any exception is thrown and we have a Model instance with setted values.

Steps to reproduce the behavior:

class User extends \Phalcon\Mvc\Model
{
    protected $id;

    public function setId($id)
    {
        throw new \Exception('Setter is called');
    }

    public function getId()
    {
        return $this->id;
    }
}

$user = User::findFirst(10);
// Exception is expected but not observed
echo $user->id;  // output: 10

$user = new User;
$user->id = 10;
// Exception is thrown as expected

Also there is another unexpected behaviour. If we override cloneResultMap method and create a new instance of base model and set a value for protected property no exception is thown as expected.

class User extends \Phalcon\Mvc\Model
{
    public static function cloneResultMap (
        $base,
        array $data,
        $columnMap,
        int $dirtyState = 0,
        bool $keepSnapshots = null
    ): \Phalcon\Mvc\ModelInterface
    {
        $class = get_class($base);
        $instance = new $class;
        $instance->id = 10; // the value is set like a public, no exception is thrown

        return $instance;
    }
}

Details
Environment:
OS: Linux UBT 4.15.0-74-generic #84-Ubuntu SMP Thu Dec 19 08:06:28 UTC 2019 x86_64
PHP Version: 7.4.2
PHP SAPI: cli
PHP Bin: /usr/bin/php7.4
PHP Extension Dir: /usr/lib/php/20190902
PHP Bin Dir: /usr/bin
Loaded PHP config: /etc/php/7.4/cli/php.ini
Versions:
Phalcon DevTools Version: 4.0.1
Phalcon Version: 4.0.3
AdminLTE Version: 2.3.6

@jaguarsdv jaguarsdv added bug A bug report status: unverified Unverified labels Feb 4, 2020
@jaguarsdv
Copy link
Author

Can be related to #14766

@ruudboon ruudboon added this to Backlog in Phalcon Roadmap Feb 4, 2020
@ruudboon ruudboon moved this from Backlog to Current Sprint (Ends February 7th) in Phalcon Roadmap Feb 4, 2020
@Jurigag
Copy link
Contributor

Jurigag commented Feb 4, 2020

@ruudboon ruudboon added status: medium Medium 4.0.4 and removed status: unverified Unverified labels Feb 7, 2020
@ruudboon ruudboon added the external dependency This issue depends on external issue to be resolved. label Feb 14, 2020
@Jeckerson Jeckerson added 4.0.5 and removed 4.0.4 labels Feb 15, 2020
@niden niden added 4.0.6 and removed 4.0.5 labels Mar 8, 2020
@sergeyklay sergeyklay self-assigned this Mar 13, 2020
@sergeyklay sergeyklay removed their assignment Mar 26, 2020
@sergeyklay
Copy link
Contributor

sergeyklay commented Apr 23, 2020

Zephir issue has been fixed in #2078. I'll release new version ASAP

@sergeyklay
Copy link
Contributor

Zephir 0.12.18 released: https://github.com/phalcon/zephir/releases/tag/0.12.18

@niden niden added 4.1.0 and removed 4.0.6 labels May 18, 2020
@zsilbi zsilbi self-assigned this Oct 6, 2020
zsilbi added a commit to zsilbi/cphalcon that referenced this issue Oct 16, 2020
@zsilbi zsilbi added 5.0 The issues we want to solve in the 5.0 release transfer and removed 4.1.0 labels Oct 16, 2020
@zsilbi zsilbi removed their assignment Oct 16, 2020
@Jeckerson Jeckerson self-assigned this Mar 27, 2021
@Jeckerson Jeckerson modified the milestone: 5.0.0 Mar 27, 2021
@niden niden moved this from Active Sprint Tasks to Working on it in Phalcon Roadmap May 25, 2021
@niden niden moved this from Working on it to Active Sprint Tasks in Phalcon Roadmap Oct 23, 2021
@Jeckerson Jeckerson removed the external dependency This issue depends on external issue to be resolved. label Oct 23, 2021
@Jeckerson Jeckerson assigned niden and Jeckerson and unassigned Jeckerson Oct 23, 2021
@niden niden moved this from Active Sprint Tasks to Working on it in Phalcon Roadmap Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Status: In Progress
Phalcon Roadmap
  
Working on it
Development

No branches or pull requests

7 participants