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]: dirty state isn't saved when serialize a model #15571

Closed
stijn1989 opened this issue Jul 1, 2021 · 1 comment · Fixed by #15780
Closed

[BUG]: dirty state isn't saved when serialize a model #15571

stijn1989 opened this issue Jul 1, 2021 · 1 comment · Fixed by #15780
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: low Low

Comments

@stijn1989
Copy link
Contributor

stijn1989 commented Jul 1, 2021

Describe the bug
When you have a form with an existing entity (state is persisted) and then you save the form in a session. When you retrieve the form on the next request (or more future requests), you get the form with it's entity. Every data is restored, except the dirty state.
This is because the serialize() method in Model class, only saves the data and not the state.
When unserializing the entity, it returns to it's default dirty state, transient.

To Reproduce

Steps to reproduce the behavior:

class Person extends \Phalcon\Model
{
    public $name;
}

....

$person  = Person::findFirst();
echo "Dirty state = " . $person->getDirtyState(); //Dirty state = 0
$serialized = serialize($person);
$person = unserialize($serialized);
echo "Dirty state = " . $person->getDirtyState(); //Dirty state = 1

Expected behavior
You should expect that the dirty state isn't changed.

$person  = Person::findFirst();
echo "Dirty state = " . $person->getDirtyState(); //Dirty state = 0
$serialized = serialize($person);
$person = unserialize($serialized);
echo "Dirty state = " . $person->getDirtyState(); //Dirty state = 0

Details

  • Phalcon version: 4.1
  • PHP Version: 7.3
  • Operating System: Debian
  • Installation type: PECL
  • Zephir version (if any):
  • Server: Nginx
  • Other related info (Database, table schema): MariaDB

Additional context
I found this out because I save my form to session and then restore it from session when submitted.
One of the entities has a validator Uniqueness validator. There is a check in which the entity is check on dirty state == 0.
So when submitted with the same value as in the database row, it failed on this validator. Because the state == 1 and so it doesn't leave out the row linked with the entity while validating.

I extended the serialize() method so it saves the dirty state. Maybe there is a reason behind this why state is not saved?

@stijn1989 stijn1989 added bug A bug report status: unverified Unverified labels Jul 1, 2021
@Jeckerson Jeckerson added the 5.0 The issues we want to solve in the 5.0 release label Nov 7, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
@niden niden added status: low Low and removed status: unverified Unverified labels Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
BeMySlaveDarlin pushed a commit to BeMySlaveDarlin/cphalcon that referenced this issue Nov 9, 2021
@niden
Copy link
Member

niden commented Nov 12, 2021

Resolved in #15780

@niden niden closed this as completed Nov 12, 2021
@niden niden moved this to Released in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
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: low Low
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants