Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-168

serialization/unserialization of ClassMetadata lose reflFields order causing insertSql statement to fail

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      This problem will be difficult to reproduce for you, but I isolated the exact cause of it.

      To reproduce

      • Use any MetadataCache
      • Create a complex entity with some inheritance. (I may detail in later if your really need it)
      • Create an element of this entity with persist.
      • Create an other element of this entity but not on the same php run. (ex: reload the page)
      • The insert statement will fail because field names will not match parameters.

      I narrowed it down to a serialization issue.

      When you serialize an MetadataInfo, you don't serialize reflFields.
      When you unserizlize you regenerate this value using ReflectionClass
      That sound's like a good optimization.

      The problem is that somehow, the reflection class can return the fields not in the same order that they were at the initial creation of the MetadataInfo.

      Because the insertSql value is not re-generated, it can be out of sync with the new fields order.

      The solution :
      Call something like MetadataInfoFactory::_generateStaticSql (whish is private but ...) at wakeup time.

        Activity

        Eric Durand-Tremblay created issue -
        Hide
        Roman S. Borschel added a comment -

        Are you using composite keys anywhere?

        The fact that reflFields is not serialized is not really an optimization but rather due to the fact that they simply can can not be serialized/unserialized properly.

        We surely need some more concrete test case in order to reproduce this.

        Show
        Roman S. Borschel added a comment - Are you using composite keys anywhere? The fact that reflFields is not serialized is not really an optimization but rather due to the fact that they simply can can not be serialized/unserialized properly. We surely need some more concrete test case in order to reproduce this.
        Hide
        Eric Durand-Tremblay added a comment -

        I do not uses composite key anyware.

        The field who change place is a foreign key.

        EntityRevision extends Entity
        EntityRevision.parent_entity : manyToOne entity

        (the field parent_entity_id changes place during serialization)

        What do you need to reproduce the case ? Just entitiy classes? a completely fuctionnal project? some kind of unit test ?

        Show
        Eric Durand-Tremblay added a comment - I do not uses composite key anyware. The field who change place is a foreign key. EntityRevision extends Entity EntityRevision.parent_entity : manyToOne entity (the field parent_entity_id changes place during serialization) What do you need to reproduce the case ? Just entitiy classes? a completely fuctionnal project? some kind of unit test ?
        Hide
        Roman S. Borschel added a comment -

        Hm. the order shouldnt even matter because insertSql only contains placeholders. Can you show the SQL INSERT that is failing? With parameters, if possible, and error message.

        Show
        Roman S. Borschel added a comment - Hm. the order shouldnt even matter because insertSql only contains placeholders. Can you show the SQL INSERT that is failing? With parameters, if possible, and error message.
        Hide
        Eric Durand-Tremblay added a comment -

        For what I can remember, parameters are not bound in the right order which is causing an error like "field x could not be null"

        INSERT INTO table (a, b) VALUES (?, ?)
        bind : $b, $a
        

        I will post the real query on monday morning when I get back to work.

        Show
        Eric Durand-Tremblay added a comment - For what I can remember, parameters are not bound in the right order which is causing an error like "field x could not be null" INSERT INTO table (a, b) VALUES (?, ?) bind : $b, $a I will post the real query on monday morning when I get back to work.
        Hide
        Eric Durand-Tremblay added a comment -

        Here is the real world example. I put the statement, the parameters, the error, and all the related entities.

        INSERT INTO fna_client_revision (fna_parent_record_id, record_id, display_name, last_name, maiden_name, first_name, civility, gender, birthdate, employer, employment, employment_from, civil_status, civil_status_from, insurability, fna_client_fna_id, fna_spouse_fna_id, rev_no, created_at, modified_at, created_by, modified_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
        
        Array
        (
            [1] => 1
            [2] => George Simard2
            [3] => Simard2
            [4] =>
            [5] => George
            [6] =>
            [7] => MALE
            [8] => 1962-09-14
            [9] => Plomberie ABC Inc.
            [10] => Plombier
            [11] =>
            [12] => MARRIED
            [13] =>
            [14] => INSURABLE
            [15] => 5
            [16] => 2009-12-07 08:54:46
            [17] => 2009-12-07 08:54:46
            [18] =>  Eric Durand-Tremblay
            [19] =>  Eric Durand-Tremblay
            [20] => 1
            [21] =>
            [22] =>
        )
        
        SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'employment' cannot be null
        
        namespace ORM\BaseEntity;
        
        /**
         * @MappedSuperclass
         */
        class Entity
        {
        	private static $boolean_values = array("YES", 'NO');
        	
        	 /**
             * @Column(name="id", type="integer")
             * @Id
             * @GeneratedValue(strategy="AUTO")
             */
            protected $id;
            
            /**
             * @Column(name="created_at", type="datetime")
             */
            protected $created_at;
            
            /**
             * @Column(name="modified_at", type="datetime")
             */
            protected $modified_at;
            
            
             /**
             * @Column(name="created_by", type="string")
             */
            protected $created_by="";
            
            /**
             * @Column(name="modified_by", type="string")
             */
            protected $modified_by="";
        }
        
        /**
         * @MappedSuperclass
         * @HasLifecycleCallbacks
         */
        class Revisionable extends ORM\BaseEntity\Entity
        {
        
             /**
             * @Column(name="rev_no", type="integer")
             */
            protected $revision=1;
        }
        
        
        namespace ORM\BaseEntity;
        
        /**
         * @MappedSuperclass
         * @HasLifecycleCallbacks
         */
        class Client extends Revisionable
        {
        
            /**
             * @Column(name="display_name", type="string")
             */
            protected $display_name;
        
            /**
             * @Column(name="last_name", type="string")
             */
            protected $last_name="";
        
            /**
             * @Column(name="maiden_name", type="string")
             */
            protected $maiden_name="";
        
            /**
             * @Column(name="first_name", type="string")
             */
            protected $first_name="";
        
            /**
             * @Column(name="civility", type="string")
             */
            protected $civility="";
            
            /**
             * @Column(name="gender", type="string", length="25")
             */
            protected $gender="";
        
            /**
             * @Column(name="birthdate", type="date", nullable="true")
             */
            protected $birthdate;
        
            /**
             * @Column(name="employer", type="string")
             */
            protected $employer="";
        
            /**
             * @Column(name="employment", type="string")
             */
            protected $employment="";
        
            /**
             * @Column(name="employment_from", type="date", nullable="true")
             */
            protected $employment_from;
        
            /**
             * @Column(name="civil_status", type="string", length="25")
             */
            protected $civil_status="";
            
            /**
             * @Column(name="civil_status_from", type="date", nullable="true")
             */
            protected $civil_status_from;
            
            /**
             * @Column(name="insurability", type="string", length="25")
             */
            protected $insurability="";
        
            
            /**
             * @OneToOne(targetEntity="ORM\Entity\FNA")
             * @JoinColumns({
             *   @JoinColumn(name="fna_client_fna_id", referencedColumnName="id")
             * })
             */
            protected $client_fna;
        
        	/**
             * @OneToOne(targetEntity="ORM\Entity\FNA")
             * @JoinColumns({
             *   @JoinColumn(name="fna_spouse_fna_id", referencedColumnName="id")
             * })
             */
            protected $spouse_fna;
        }
        
        
        namespace ORM\RevisionEntity;
        
        /**
         * @Entity
         * @Table(name="fna_client_revision", indexes={@index(name="idx_record_id", columns={"record_id"})})
         * @HasLifecycleCallbacks
         */
        class Client extends ORM\BaseEntity\Client{
        	
        	 /**
             * @ManyToOne(targetEntity="Kronos\FNA\ORM\Entity\Client")
             * @JoinColumns({
             *   @JoinColumn(name="fna_parent_record_id", referencedColumnName="id", onDelete="SET NULL")
             * })
             */
            protected $parent_record;  /// HERE IS THE  FIELD WHO CHANGE PLACE AFTER SERIALIZATION !!!!!!!!!!!!!!!!!!!!!!
            
            /**
             * 
             * @Column(name="record_id", type="int")
             */
            protected $record_id;
        }
        
        
        Show
        Eric Durand-Tremblay added a comment - Here is the real world example. I put the statement, the parameters, the error, and all the related entities. INSERT INTO fna_client_revision (fna_parent_record_id, record_id, display_name, last_name, maiden_name, first_name, civility, gender, birthdate, employer, employment, employment_from, civil_status, civil_status_from, insurability, fna_client_fna_id, fna_spouse_fna_id, rev_no, created_at, modified_at, created_by, modified_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Array ( [1] => 1 [2] => George Simard2 [3] => Simard2 [4] => [5] => George [6] => [7] => MALE [8] => 1962-09-14 [9] => Plomberie ABC Inc. [10] => Plombier [11] => [12] => MARRIED [13] => [14] => INSURABLE [15] => 5 [16] => 2009-12-07 08:54:46 [17] => 2009-12-07 08:54:46 [18] => Eric Durand-Tremblay [19] => Eric Durand-Tremblay [20] => 1 [21] => [22] => ) SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'employment' cannot be null namespace ORM\BaseEntity; /** * @MappedSuperclass */ class Entity { private static $boolean_values = array( "YES" , 'NO'); /** * @Column(name= "id" , type= "integer" ) * @Id * @GeneratedValue(strategy= "AUTO" ) */ protected $id; /** * @Column(name= "created_at" , type= "datetime" ) */ protected $created_at; /** * @Column(name= "modified_at" , type= "datetime" ) */ protected $modified_at; /** * @Column(name= "created_by" , type= "string" ) */ protected $created_by=""; /** * @Column(name= "modified_by" , type= "string" ) */ protected $modified_by=""; } /** * @MappedSuperclass * @HasLifecycleCallbacks */ class Revisionable extends ORM\BaseEntity\Entity { /** * @Column(name= "rev_no" , type= "integer" ) */ protected $revision=1; } namespace ORM\BaseEntity; /** * @MappedSuperclass * @HasLifecycleCallbacks */ class Client extends Revisionable { /** * @Column(name= "display_name" , type= "string" ) */ protected $display_name; /** * @Column(name= "last_name" , type= "string" ) */ protected $last_name=""; /** * @Column(name= "maiden_name" , type= "string" ) */ protected $maiden_name=""; /** * @Column(name= "first_name" , type= "string" ) */ protected $first_name=""; /** * @Column(name= "civility" , type= "string" ) */ protected $civility=""; /** * @Column(name= "gender" , type= "string" , length= "25" ) */ protected $gender=""; /** * @Column(name= "birthdate" , type= "date" , nullable= " true " ) */ protected $birthdate; /** * @Column(name= "employer" , type= "string" ) */ protected $employer=""; /** * @Column(name= "employment" , type= "string" ) */ protected $employment=""; /** * @Column(name= "employment_from" , type= "date" , nullable= " true " ) */ protected $employment_from; /** * @Column(name= "civil_status" , type= "string" , length= "25" ) */ protected $civil_status=""; /** * @Column(name= "civil_status_from" , type= "date" , nullable= " true " ) */ protected $civil_status_from; /** * @Column(name= "insurability" , type= "string" , length= "25" ) */ protected $insurability=""; /** * @OneToOne(targetEntity= "ORM\Entity\FNA" ) * @JoinColumns({ * @JoinColumn(name= "fna_client_fna_id" , referencedColumnName= "id" ) * }) */ protected $client_fna; /** * @OneToOne(targetEntity= "ORM\Entity\FNA" ) * @JoinColumns({ * @JoinColumn(name= "fna_spouse_fna_id" , referencedColumnName= "id" ) * }) */ protected $spouse_fna; } namespace ORM\RevisionEntity; /** * @Entity * @Table(name= "fna_client_revision" , indexes={@index(name= "idx_record_id" , columns={ "record_id" })}) * @HasLifecycleCallbacks */ class Client extends ORM\BaseEntity\Client{ /** * @ManyToOne(targetEntity= "Kronos\FNA\ORM\Entity\Client" ) * @JoinColumns({ * @JoinColumn(name= "fna_parent_record_id" , referencedColumnName= "id" , onDelete= "SET NULL" ) * }) */ protected $parent_record; /// HERE IS THE FIELD WHO CHANGE PLACE AFTER SERIALIZATION !!!!!!!!!!!!!!!!!!!!!! /** * * @Column(name= "record_id" , type= " int " ) */ protected $record_id; }
        Hide
        Eric Durand-Tremblay added a comment -
           
            [1] => 1  (fna_parent_record_id)
        (expected record_id)
            [2] => George Simard2 (display_name)
            [3] => Simard2 (last_name)
            [4] => (maiden_name)
            [5] => George (first_name)
            [6] => (civility)
            [7] => MALE (gender)
            [8] => 1962-09-14 (birthdate)
            [9] => Plomberie ABC Inc. (employer)
            [10] => Plombier (employment)
            [11] => (employment_from)
            [12] => MARRIED (civil_status)
            [13] => (civil_status_from)
            [14] => INSURABLE (insurability)
            [15] => 5 (rev_no)
            [16] => 2009-12-07 08:54:46 (created_at)
            [17] => 2009-12-07 08:54:46 (modified_at)
            [18] =>  Eric Durand-Tremblay (created_by)
            [19] =>  Eric Durand-Tremblay (modified_by)
            [20] => 1 (record_id) !! Should be in position  2
            [21] => (fna_client_fna_id)
            [22] => (fna_spouse_fna_id)
        
        
        Show
        Eric Durand-Tremblay added a comment - [1] => 1 (fna_parent_record_id) (expected record_id) [2] => George Simard2 (display_name) [3] => Simard2 (last_name) [4] => (maiden_name) [5] => George (first_name) [6] => (civility) [7] => MALE (gender) [8] => 1962-09-14 (birthdate) [9] => Plomberie ABC Inc. (employer) [10] => Plombier (employment) [11] => (employment_from) [12] => MARRIED (civil_status) [13] => (civil_status_from) [14] => INSURABLE (insurability) [15] => 5 (rev_no) [16] => 2009-12-07 08:54:46 (created_at) [17] => 2009-12-07 08:54:46 (modified_at) [18] => Eric Durand-Tremblay (created_by) [19] => Eric Durand-Tremblay (modified_by) [20] => 1 (record_id) !! Should be in position 2 [21] => (fna_client_fna_id) [22] => (fna_spouse_fna_id)
        Hide
        Benjamin Eberlei added a comment -

        I could reproduce the issue and generated a failing test for this. We already discussed how this might be fixed.

        Show
        Benjamin Eberlei added a comment - I could reproduce the issue and generated a failing test for this. We already discussed how this might be fixed.
        Hide
        Eric Durand-Tremblay added a comment -

        This is a very good news !

        Show
        Eric Durand-Tremblay added a comment - This is a very good news !
        Roman S. Borschel made changes -
        Field Original Value New Value
        Fix Version/s 2.0-ALPHA4 [ 10036 ]
        Roman S. Borschel made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Roman S. Borschel added a comment -

        Should be fixed now.

        Show
        Roman S. Borschel added a comment - Should be fixed now.
        Roman S. Borschel made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Hide
        Eric Durand-Tremblay added a comment -

        Resolution confirmed.

        Thank your for your great work !

        Show
        Eric Durand-Tremblay added a comment - Resolution confirmed. Thank your for your great work !
        Benjamin Eberlei made changes -
        Workflow jira [ 10483 ] jira-feedback [ 15490 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15490 ] jira-feedback2 [ 17354 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17354 ] jira-feedback3 [ 19611 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-168, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Eric Durand-Tremblay
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: