jonathangeiger / kohana-jelly

See the link below for the most up-to-date code
https://github.com/creatoro/jelly
MIT License
146 stars 34 forks source link

[Unstable] Problem with _validator on serialized models #170

Open Neurergus opened 14 years ago

Neurergus commented 14 years ago

Hi,

In my app, I use the module A1 as the auth system, with a custom driver for Jelly (nothing special). When I log in, the user model is serialized into the session.

One of the fields of the model is a Field_Image type that strictly needs the callback function _upload to return a valid name, or else you end with this:

Database_Exception [ 1241 ]: Operand should contain 1 column(s)
[ UPDATE `users` SET `logo` = ('265432t9h9b8c.jpg', 'image/jpeg', '/tmp/phppiNo2R', 0, 11910) WHERE `users`.`id` = 2814

The problem is that when I try to modify the logo of the object in the session (logged user), the callbacks are never called.

Normally, when _validator is created, you obtain something like this:

object Jelly_Validator
(
    $_validate = array
    (
        [..]

        'rule' = array
        (
            // Lots of rules
        ),

        'callback' = array
        (
            // Lots of callbacks
        )
    )

    [...]
)

But, in that case, the _validator contains:

object Jelly_Validator
(
    'logo' = array
    (
        'name' = 'Balbalba',
        [...]
    )
)

For now, the poorly temp fix I found is to extend the core Model and Meta classes of Jelly, and add this magic method:

public function __wakeup()
{
    $this->_validator = NULL;
}

This way the _validator property is regenerated "every time", and it works.

One curious thing. On my machine it works flawessly without this modifications, but in the two different hosts I tried, I see that bothering error. The difference: my machine has php version 5.3.3 and the other two 5.2.13.

I wish I could say something more useful.

jonathangeiger commented 14 years ago

Thanks for this. Looks to be a genuine bug.

Neurergus commented 14 years ago

Hi,

Upgrading the hosting machine to php 5.3 apparently solved this problem.

Also, my commented "temp fix" is pure shit, read the unpleasant consequences here: http://forum.kohanaframework.org/discussion/6984/solved-session-problem-in-kohana-3.0.8/

jonathangeiger commented 14 years ago

I'm a bit confused here. Are you saying that this

public function __wakeup()
{
    $this->_validator = NULL;
}

Doesn't work as a fix? I don't really see why it wouldn't.

It looks like this bug might be related.

Neurergus commented 14 years ago

It fixes this problem, but as you can see in the kohana forums, causes another. But it was a temporary thing anyway.

Yes, probably all this is caused by that php bug.