Skip to content

serialize/unserialize of records with 'array' columns failsΒ #53

@tlt-miamed

Description

@tlt-miamed

This bug happens only on edge cases. Let me describe the scenario first:

schema.yml:

Model:
  columns:
    details: { type: array, notnull: true }
  options:
    symfony: { form: false, filter: false }
    type: InnoDB


RelatedModel:
  columns:
    model_id: { type: integer(8), unsigned: true, notnull: true }
  relations:
    Model:    { class: Model, foreign: id, local: model_id, foreignAlias: RelatedModels, type: one, foreignType: many }
  options:
    symfony:  { form: false, filter: false }
    type: InnoDB

Important here is that 'Model' contains a column of type 'array' and 'Model' has a 'RelatedModel'.

Now the database content:
The database should contain at least one 'Model' (id: 1) connected with one 'RelatedModel' (id: 1).
The 'Model'.'details' should contain an array with at least 20 entries.

Now lets provoke the error. I found these two methods:

Method 1: Load form database with cache
If this query hits the cache the unserialize will fail.

$foo = ModelTable::getInstance()
    ->createQuery('m')
    ->leftJoin('m.RelatedModels rm')
    ->select('m.id, m.details, rm.id')
    ->where('m.id = ?', 1)
    ->useResultCache(true)
    ->execute();

Method 2: serialize/unserialize with references

$foo = ModelTable::getInstance()
    ->createQuery('m')
    ->leftJoin('m.RelatedModels rm')
    ->select('m.id, m.details, rm.id')
    ->where('m.id = ?', 1)
    ->execute();

$foo->serializeReferences(true);
unserialize(serialize($foo));

both of these examples will create an error similar to this:

>> sfWebDebugLogger  Notice at /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php on line 176 (unserialize(): Error at offset 596 of 657 bytes)
NOTICE |13:06:01: {sfWebDebugLogger}  Notice at /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php on line 176 (unserialize(): Error at offset 596 of 657 bytes)

Notice: unserialize(): Error at offset 596 of 657 bytes in /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php on line 176

Call Stack:
    0.0005     241824   1. {main}() /workdir/symfony:0
    0.3185   25599144   2. sfSymfonyCommandApplication->run() /workdir/symfony:19
    0.3207   25603696   3. sfTask->runFromCLI() /workdir/vendor/lexpress/symfony1/lib/command/sfSymfonyCommandApplication.class.php:76
    0.3207   25605088   4. sfBaseTask->doRun() /workdir/vendor/lexpress/symfony1/lib/task/sfTask.class.php:98
    0.3664   37410728   5. testTask->execute() /workdir/vendor/lexpress/symfony1/lib/task/sfBaseTask.class.php:70
    0.3757   39949400   6. Doctrine_Query_Abstract->execute() /workdir/lib/task/testTask.class.php:45
    0.6709   42200896   7. Doctrine_Query_Abstract->_constructQueryFromCache() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Query/Abstract.php:1085
    0.6709   42200944   8. unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Query/Abstract.php:1235
    0.6717   42437752   9. Doctrine_Collection->unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Query/Abstract.php:1235
    0.6717   42437800  10. unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php:176
    0.6718   42441352  11. Doctrine_Record->unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php:176
    0.6718   42441968  12. unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Record.php:869
    0.6718   42455632  13. Doctrine_Collection->unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Record.php:869
    0.6718   42455680  14. unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php:176

>> sfWebDebugLogger  Warning at /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php on line 178 (Invalid argument supplied for foreach())
WARNING|13:06:01: {sfWebDebugLogger}  Warning at /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php on line 178 (Invalid argument supplied for foreach())

Warning: Invalid argument supplied for foreach() in /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php on line 178

Call Stack:
    0.0005     241824   1. {main}() /workdir/symfony:0
    0.3185   25599144   2. sfSymfonyCommandApplication->run() /workdir/symfony:19
    0.3207   25603696   3. sfTask->runFromCLI() /workdir/vendor/lexpress/symfony1/lib/command/sfSymfonyCommandApplication.class.php:76
    0.3207   25605088   4. sfBaseTask->doRun() /workdir/vendor/lexpress/symfony1/lib/task/sfTask.class.php:98
    0.3664   37410728   5. testTask->execute() /workdir/vendor/lexpress/symfony1/lib/task/sfBaseTask.class.php:70
    0.3757   39949400   6. Doctrine_Query_Abstract->execute() /workdir/lib/task/testTask.class.php:45
    0.6709   42200896   7. Doctrine_Query_Abstract->_constructQueryFromCache() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Query/Abstract.php:1085
    0.6709   42200944   8. unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Query/Abstract.php:1235
    0.6717   42437752   9. Doctrine_Collection->unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Query/Abstract.php:1235
    0.6717   42437800  10. unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php:176
    0.6718   42441352  11. Doctrine_Record->unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php:176
    0.6718   42441968  12. unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Record.php:869
    0.6718   42455632  13. Doctrine_Collection->unserialize() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Record.php:869


06.09.2018 01:06:01 - Task ./symfony, t:t caught exception of class Doctrine_Exception with message Couldn't find class /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Table.php 310
#0 /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Table.php(261): Doctrine_Table->initDefinition()
#1 /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Connection.php(1148): Doctrine_Table->__construct(NULL, Object(Doctrine_Connection_Mysql), true)
#2 /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php(182): Doctrine_Connection->getTable(NULL)
#3 [internal function]: Doctrine_Collection->unserialize('a:6:{s:4:"data"...')
#4 /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Record.php(869): unserialize('a:15:{s:3:"_id"...')
#5 [internal function]: Doctrine_Record->unserialize('a:15:{s:3:"_id"...')
#6 /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Collection.php(176): unserialize('a:6:{s:4:"data"...')
#7 [internal function]: Doctrine_Collection->unserialize('a:6:{s:4:"data"...')
#8 /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Query/Abstract.php(1235): unserialize('a:3:{i:0;C:31:"...')
#9 /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Query/Abstract.php(1085): Doctrine_Query_Abstract->_constructQueryFromCache('a:3:{i:0;C:31:"...')
#10 /workdir/lib/task/testTask.class.php(45): Doctrine_Query_Abstract->execute()
#11 /workdir/vendor/lexpress/symfony1/lib/task/sfBaseTask.class.php(70): testTask->execute(Array, Array)
#12 /workdir/vendor/lexpress/symfony1/lib/task/sfTask.class.php(98): sfBaseTask->doRun(Object(sfCommandManager), NULL)
#13 /workdir/vendor/lexpress/symfony1/lib/command/sfSymfonyCommandApplication.class.php(76): sfTask->runFromCLI(Object(sfCommandManager), NULL)
#14 /workdir/symfony(19): sfSymfonyCommandApplication->run()
#15 {main}

                        
  Couldn't find class   
                        


Fatal error: Call to a member function evictAll() on null in /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Connection.php on line 1267

Call Stack:
    0.0005     241824   1. {main}() /workdir/symfony:0
    1.0430   42803488   2. sfDatabaseManager->shutdown() /workdir/vendor/lexpress/symfony1/lib/database/sfDatabaseManager.class.php:0
    1.0430   42803616   3. sfDoctrineDatabase->shutdown() /workdir/vendor/lexpress/symfony1/lib/database/sfDatabaseManager.class.php:137
    1.0430   42803792   4. Doctrine_Manager->closeConnection() /workdir/vendor/lexpress/symfony1/lib/plugins/sfDoctrinePlugin/lib/database/sfDoctrineDatabase.class.php:152
    1.0430   42803976   5. Doctrine_Connection->close() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Manager.php:583
    1.0430   42804560   6. Doctrine_Connection->clear() /workdir/vendor/lexpress/doctrine1/lib/Doctrine/Connection.php:1296

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions