-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syncdata unable to use natural keys #1549
Comments
Would restructuring the code to not use Could you make a PR for at least a test case ? |
Created a PR #1551 with a failing test, but I'm not sure how to go about restructuring the code to allow both the I'm actually not clear on the use-case that One alternative technique is just wiping the relevant tables before loading the fixture, rather than trying to identify which objects to keep and which to delete. I'm assuming the current method is for performance reasons, but since all the kept objects are iterated through and re-saved anyway, I don't know how much of slower it would be to just delete everything and add back what's in the fixture? |
This was the originating PR; #1529 @cuchi could you please help here with a background information and @MattFisher's questions ? Reading that PR and this issue it kinda sounds to me that there is a more fundamental problem (and therefor fix) for this in the code... Given that the original intend was to fix issues with some constraint conditions and that fix breaking natural keys... Also looking at the code it would seem that a somewhat hacky solution could be to revert to the original code and just do a 2 phase approach for the But as said that feels even more hacky, where probably the best solution is to see why the entire process is troublesome in the case of fixtures with constraint on another existing object... Anyways I hope @cuchi can help shed some light on this :-) |
Thanks for pointing out that PR @trbs, I understand the requirement that prompted the addition of I've added a failing test covering the scenario. |
Version 3 seems unable to use natural keys in
syncdata
fixtures.The traceback shows a long string of "During handling of the above exception, another exception occurred", but the important bits are:
I think this is because of the changes made here 0edbb6c#diff-ed4bf9a1cad19a0969a26b755518c4a9R164, in adding the
remove_before
flag.In django's
loaddata
, it uses the construct:serializers.deserialize()
returns a generator, and relies internally on all the previous objects already being saved before generating each one. The change insyncdata
to materialise the objects into a list before saving them means natural key lookups can't work.Minimal fixture demonstrating the problem:
The text was updated successfully, but these errors were encountered: