Never trust doctrine:data-dump…

…and especially not if you get the impression that the dump will afterwards be readable by the doctrine:data-load command of symfony.

It was a costly lesson today when I tried to reimport a dump of a couple of Sympal tables. One of them, the one which models the menu items, has a nested set behaviour, and apparently this one cannot be restored properly by doctrine:

Unknown record property / related component "children" on "sfSympalMenuItem"

Apparently this particular issue popped up a couple of times in the past for other people as well (Google for it) and while the help of doctrine:data-dump still (Doctrine 1.2) blatantly states

The doctrine:data-dump task dumps database data:

 ./symfony doctrine:data-dump

The task dumps the database data in data/fixtures/%target%.

The dump file is in the YML format and can be reimported
by using the doctrine:data-load task.

 ./symfony doctrine:data-load

(with the emphasis of “can be reimported”)

the author of Doctrine, Jonathan Wage, told me today on Sympal’s IRC (shortened):

<jonwage> we don’t want people to think you can dump and then restore
<jonwage> that is not what the data fixtures are for
<jonwage> b/c dumping and then loading will never work
<jonwage> an ORM modifies data on the way and and the way out
<me> I mean the least thing doctrine could do there is that if it detects the nested set behaviour it should error out clearly on dump
<jonwage> so you can’t dump the data through an ORM and then try and reload it
<jonwage> i.e. hashed passwords
<me> if dumping is “never” going to work – why do you support dumping into yaml at all?!
<jonwage> if we do that then we would have to throw errors in sooooooo many other cases too
<jonwage> because it is at least a little bit of a convenience
<me> its like a half-baked feature then
<jonwage> we dump the raw data
<jonwage> and you can tweak it
<jonwage> thats my point though, it will ALWAYS be a half baked feature thats why we document it that way
<jonwage> it can NEVER work 100% the way you want it to
<jonwage> so if we fix that one thing, a million other things will be reported that we cannot fix
<jonwage> bc an ORM is not a backup and restore tool
<jonwage> it is impossible

Now I know that as well. My only problem was that I struggled “what is wrong with my fixtures” the whole time and never dared to ask “what is wrong with doctrine”…

3 thoughts on “Never trust doctrine:data-dump…”

  1. Not much wrong with Doctrine indeed. What’s most probably missing in your fixtures is the “NestedSet: true” (yes, in your fixture datas) if your first menu item has no children.

    And yes, that’s in the documentation.

    Hope that solves

  2. Hehe, its always easy once you know the keyword, heh :)

    You’re right, it seems to be documented here, but then I still wonder why doctrine:dump just does not set this attribute. Anyways, I’m over it, I won’t have to repeat this task again…

  3. Thanks Thomas. Just came across this myself after dumping the tables for lyMediaManagerPlugin. I tried rebuilding the pg database, only to get the ‘children’ error. I agree that data dumping is not the same as a backup, but shouldn’t this work?

    Ah well, I fixed up the dump it had made by removing the left/right/level columns for each child, and adding in some children: keys. No ‘NestedSet’ keys required, and now all seems to work.

    Cheers for your post!

Comments are closed.