Circularly dependent fixtures fail due to transaction committing on each object save
|Reported by:||Michael Angeletti||Owned by:||Aymeric Augustin|
|Component:||Database layer (models, ORM)||Version:||1.6-alpha-1|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
manage.py loaddata to load a fixture that contains 2 objects that refer to each other circularly via foreign keys you'll encounter an integrity error. This is caused by the use of
transaction.commit_on_success_unless_managed in the
loaddata management command combined with the use of it in
Model.save_base, which after each save leads to a transaction commit.
When I modified the
loaddata management command to use
transaction.atomic in lieu of
transaction.commit_on_success_unless_managed the issue no longer occurred. I realize that isn't the solution (for backwards compatibility reasons), but it might help in debugging. Also, see the printed stack frames and debugging values in this post (full thread here).
This affects at least Django 1.6a1. A similar exception was encountered with Django 1.5.1, though something was subtly different about the issue in Django 1.5.1 (wasn't provided a stack trace to verify it was the same issue).
Change History (11)
comment:4 Changed 3 years ago by
|Owner:||changed from nobody to Aymeric Augustin|
|Status:||new → assigned|
comment:7 Changed 3 years ago by
|Severity:||Normal → Release blocker|
|Triage Stage:||Unreviewed → Accepted|
|Type:||Uncategorized → Bug|