Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1022

Wakeup behavior difference between proxy and eager-loaded instance

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Git Master
    • Fix Version/s: 2.0.7, 2.1.1, 2.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      When an object is reconstituted from the persistent storage the unserialize trick is used. That means __wakeup() is called, which is useful to do further initialization as needed.

      If the object is lazy loaded a proxy is generated. That proxy is generated with new and thus no _wakeup() is called. When the proxy is eventually initialized still no call to _wakeup() is done, thus initialization code that is "usually" executed is not called when an object is lazy-loaded.

      That is a semantical error.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        __wakeup() shouldn't be used as per definition of an entity, http://www.doctrine-project.org/docs/orm/2.0/en/cookbook/implementing-wakeup-or-clone.html

        For post initialization "postLoad()" should be used.

        Show
        Benjamin Eberlei added a comment - __wakeup() shouldn't be used as per definition of an entity, http://www.doctrine-project.org/docs/orm/2.0/en/cookbook/implementing-wakeup-or-clone.html For post initialization "postLoad()" should be used.
        Hide
        Karsten Dambekalns added a comment -

        You write shouldn't be used, but that seems somewhat strange, given that the page you point to explicitly says However, it is quite easy to make use of these methods in a safe way by guarding the custom wakeup or clone code with an entity identity check, as demonstrated in the following sections.

        And still the issue remains that eager-loaded instances created with the unserialize trick do call wakeup() (of course) but this does not happen when being lazy-loaded. Inconsistency, it screams...

        Show
        Karsten Dambekalns added a comment - You write shouldn't be used , but that seems somewhat strange, given that the page you point to explicitly says However, it is quite easy to make use of these methods in a safe way by guarding the custom wakeup or clone code with an entity identity check, as demonstrated in the following sections. And still the issue remains that eager-loaded instances created with the unserialize trick do call wakeup() (of course) but this does not happen when being lazy-loaded. Inconsistency , it screams...
        Hide
        Benjamin Eberlei added a comment -

        I changed my mind, this is valid

        Show
        Benjamin Eberlei added a comment - I changed my mind, this is valid
        Hide
        Benjamin Eberlei added a comment -

        Fixed in 2.0.7, 2.1.1 and in master

        Show
        Benjamin Eberlei added a comment - Fixed in 2.0.7, 2.1.1 and in master

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Karsten Dambekalns
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: