Ticket #1666 (closed defect: fixed)

Opened 8 months ago

Last modified 7 months ago

Data Export Doesn't export the keys correctly.

Reported by: marijn Owned by: jwage
Priority: major Milestone: 1.0.6
Component: Import/Export Version: 1.0.3
Severity: Keywords: export data fixture
Cc: Has Test: no
Status: Pending Core Response Has Patch: no

Description

Problem set:

I'm using Doctrine in combination with symfony, when exporting data the following errors occur:

$ symfony doctrine:data-dump ApplicationName fixture_file.yml
>> Invalid argument supplied for foreach() in plugins/sfDoctrinePlugin/lib/doctrine/Doctrine/Data/Export.php on line 163
>> doctrine  Dumped data successfully to: /data/fixtures/fixture_file.yml

I've had a look at that line but the only thing happening there is a toArray(false) call on the Doctrine_Record that is to be exported.

The fixture file that is produced is unusable. If I call a reload procedure it doesn't load the data.

Example:

The error can be regenerated with the following schema:

Asset:
  columns:
    id:             { type: integer, length: 4, primary: true, autoincrement: true }
    name:           { type: string, length: 255 }
    description:    { type: string, length: 255 }
    mime_type:      { type: enum, values: [ image/jpeg, image/png, image/gif ] }
  actAs:
    Versionable:    { versionColumn: version, className: %CLASS%Version, auditLog: true }
    Sluggable:      { unique: true, fields: [ name ], canUpdate: false }
    Timestampable:  { created: { name: created_at }, updated: { name: updated_at } }
    SoftDelete:     {  }

ImageAsset:
  inheritance:
    extends:        Asset
    type:           column_aggregation
    keyField:       content_type
    keyValue:       1

Create the following fixture files, 001_assets.yml:

Asset: {  }

002_image_assets.yml:

ImageAsset:
  test_image_asset_1:
    name:         Test Image 1
    description:  Description Test Image 1
    mime_type:    image/jpeg
  test_image_asset_2:
    name:         Test Image 2
    description:  Description Test Image 2
    mime_type:    image/gif
  test_image_asset_3:
    name:         Test Image 3
    description:  Description Test Image 3
    mime_type:    image/png

Rebuild the model:

$ symfony doctrine:build-all-reload ApplicationName

Check if all is loaded correctly:

$ symfony doctrine:dql Test "SELECT a.* FROM Asset a"

Drop the data

$ symfony doctrine:data-dump ApplicationName incorrect_data.yml
>> Invalid argument supplied for foreach() in plugins/sfDoctrinePlugin/lib/doctrine/Doctrine/Data/Export.php on line 163
>> doctrine  Dumped data successfully to: /data/fixtures/incorrect_data.yml

Try to reload:

$ symfony doctrine:build-all-reload ApplicationName
>>`Invalid row key specified: ImageAsset_1`

The error is the result of the incorrect keys in the generated fixtures file.

Environment:

Attachments

Doctrine_Data_Export.patch (0.7 KB) - added by eib 7 months ago.
Patch to Doctrine_Data_Export.php (partially fixes #1666).

Change History

Changed 7 months ago by eib

I had similar problems with dump-data; it occurs with column aggregate inheritance (possibly simple inheritance, as well).

The problem occurs because when preparing to dump-data, you iterate over the same database "rows" multiple times, e.g. you findAll rows in Asset, then all rows in ImageAsset. But after one iteration, Doctrine_Record::free gets called (line 200) which frees your Asset rows before you can process them as ImageAssets.

I'm attaching a simple patch that helps me out, but I'm not using Versionable like you are. When using your schema/fixtures, I get the following unique key constraint problems when I dump-data and subsequently build-all-reload:

SQLSTATE[23000]: Integrity constraint violation: 19 columns id, version are not unique

Changed 7 months ago by eib

Patch to Doctrine_Data_Export.php (partially fixes #1666).

Changed 7 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [5306]) [1.0, 1.1] Removing free() from data exporting as it causes problems when dealing with inheritance (closes #1666)

Changed 7 months ago by jwage

  • milestone changed from 1.0.5 to 1.0.6
Note: See TracTickets for help on using tickets.