Skip to content

[BUG]: getSnapshotData returns null #15837

@Nialld

Description

@Nialld

model getSnapshotData under some situations returns null , should be array otherwise calls getChangedFIelds throws "The 'keepSnapshots' option must be enabled to track changes"

the way serialize and unserialize work in Model.zep seem to be the problem

The first time i serialize a model , the attributes and snapshot seem to be identical, leaving the snapshot variable serialised in a null state

Follow up with an unserialize, then snapshot property is null, breaking calls to getChangedFIelds / hasChanged etc

i believe the default state of snapshot should not be null in serialize function as below.

public function serialize() -> string
    {
        /**
         * Use the standard serialize function to serialize the array data
         */
        var attributes, manager, dirtyState, snapshot = null;

        let attributes = this->toArray(),
            dirtyState = this->dirtyState,
            manager = <ManagerInterface> this->getModelsManager(),
            snapshot = [];

        if manager->isKeepingSnapshots(this) && this->snapshot != null && attributes != this->snapshot {
            let snapshot = this->snapshot;
        }

        return serialize(
            [
                "attributes":  attributes,
                "snapshot":    snapshot,
                "dirtyState":  dirtyState
            ]
        );
    }

Details

  • Phalcon version: 5.0.0alpha7
  • PHP Version: 8.0.14
  • Operating System: Ubuntu 20.04
  • Installation type: Compiled from source
  • Zephir version (if any):
  • Server: Nginx

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasebugA bug reportstatus: mediumMedium

Type

No fields configured for Bug.

Projects

Status
Released

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions