Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1734

Uninitialized proxies cannot be serialized properly

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I have the following entity:

      class Currency
      {
          /** @Id @Column(type="string") */
          protected $code;
              
          /** @Column(type="string") */    
          protected $name;
      }
      

      When I serialize an object graph which references a Currency proxy, but this proxy is initialized, then this works as expected:

      O:65:"Application\Domain\Proxy\__CG__\Application\Domain\Model\Currency":3:{s:17:"__isInitialized__";b:1;s:7:"*code";s:3:"USD";s:7:"*name";s:20:"United States Dollar";}
      

      However, if the proxy is not initialized, then all properties are serialized as null, and the identity is lost:

      O:65:"Application\Domain\Proxy\__CG__\Application\Domain\Model\Currency":3:{s:17:"__isInitialized__";b:0;s:7:"*code";N;s:7:"*name";N;}
      

      That makes a merge() impossible once stored in a session, as the identity of the entity is now unknown.

      I think the solution might be:

      • either to have the proxy's $_identity field serialized as well
      • or to have the $code (identity field) populated when the proxy is created.

        Activity

        Benjamin Morel created issue -
        Benjamin Morel made changes -
        Field Original Value New Value
        Description I have the following entity:

        {code}
        class Currency
        {
            /** @Id @Column(type="string") */
            protected $code;
                
            /** @Column(type="string") */
            protected $name;
        }
        {code}

        When I serialize an object graph which references a Currency proxy, but this proxy is initialized, then this works as expected:

        {code}
        O:65:"Application\Domain\Proxy\__CG__\Application\Domain\Model\Currency":3:{s:17:"__isInitialized__";b:1;s:7:"*code";s:3:"USD";s:7:"*name";s:20:"United States Dollar";}
        {code}

        However, if the proxy is not initialized, then all properties are serialized as null, and the identity is lost:

        {code}
        O:65:"Application\Domain\Proxy\__CG__\Application\Domain\Model\Currency":3:{s:17:"__isInitialized__";b:0;s:7:"*code";N;s:7:"*name";N;}
        {code}

        That makes a merge() impossible once stored in a session, as the identity of the entity is now unknown.

        I think the solution might be:
        - either to have the proxy's "_identity" field serialized as well
        - or to have the "code" (identity field) populated when the proxy is created.
        I have the following entity:

        {code}
        class Currency
        {
            /** @Id @Column(type="string") */
            protected $code;
                
            /** @Column(type="string") */
            protected $name;
        }
        {code}

        When I serialize an object graph which references a Currency proxy, but this proxy is initialized, then this works as expected:

        {code}
        O:65:"Application\Domain\Proxy\__CG__\Application\Domain\Model\Currency":3:{s:17:"__isInitialized__";b:1;s:7:"*code";s:3:"USD";s:7:"*name";s:20:"United States Dollar";}
        {code}

        However, if the proxy is not initialized, then all properties are serialized as null, and the identity is lost:

        {code}
        O:65:"Application\Domain\Proxy\__CG__\Application\Domain\Model\Currency":3:{s:17:"__isInitialized__";b:0;s:7:"*code";N;s:7:"*name";N;}
        {code}

        That makes a merge() impossible once stored in a session, as the identity of the entity is now unknown.

        I think the solution might be:
        - either to have the proxy's $_identity field serialized as well
        - or to have the $code (identity field) populated when the proxy is created.
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Can't Fix [ 7 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13570 ] jira-feedback [ 15292 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15292 ] jira-feedback2 [ 17156 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17156 ] jira-feedback3 [ 19410 ]
        Marco Pivetta made changes -
        Resolution Can't Fix [ 7 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Marco Pivetta made changes -
        Status Reopened [ 4 ] Awaiting Feedback [ 10000 ]
        Marco Pivetta made changes -
        Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
        Marco Pivetta made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Fix Version/s 2.4 [ 10321 ]

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Benjamin Morel
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: