Fixes unexpected deletion of related objects.#97
Fixes unexpected deletion of related objects.#97gibsonbailey wants to merge 2 commits intobeda-software:masterfrom
Conversation
…king to the instance should not be deleted. Instead, the foreign key should simply be removed from the objects to the instance. This commit checks if the related field is a foreign key, and, if so, it unlinks the object. If the field cannot be null, the object gets deleted.
Codecov Report
@@ Coverage Diff @@
## master #97 +/- ##
==========================================
+ Coverage 98.59% 98.61% +0.01%
==========================================
Files 3 3
Lines 213 216 +3
==========================================
+ Hits 210 213 +3
Misses 3 3
Continue to review full report at Codecov.
|
|
@gibsonbailey Thanks for the contribution. Could you please add a failing test which is fixed with your changes? |
|
Yes, thanks for the consideration. |
…gn key, i.e. s, are not deleted when they are removed from a profile.
|
@ruscoder Test has been added. Thanks Vadim! |
|
@gibsonbailey Thanks for the tests. With CASCADE, Django deletes the instance if the related instance is deleted. To avoid this you should pass So, I think the logic should be changed to use |
|
My comment is still actual. So I don't close it and don't accept for now. |
When updating an instance with foreign key relations, the objects linking to the instance should not be deleted. Instead, the foreign key should simply be removed from the objects to the instance. This commit checks if the related field is a foreign key, and, if so, it unlinks the object. If the field cannot be null, the object still gets deleted, as it does in the current state of the master branch.