-
Notifications
You must be signed in to change notification settings - Fork 438
Fix IntegrityError when cloning objects with pk=None (#664) #707
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #707 +/- ##
==========================================
+ Coverage 95.21% 95.54% +0.32%
==========================================
Files 31 33 +2
Lines 1025 1101 +76
==========================================
+ Hits 976 1052 +76
Misses 49 49 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| def test_create_duplicate_with_pk_none(self): | ||
| pass | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this test here do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It disables test_create_duplicate_with_pk_none test for models which have another model as primary key (ModelPrimaryKeyModel).
| obj = self.obj | ||
| obj.pk = None | ||
| obj.save() | ||
| self.assertEqual(LogEntry.objects.count(), initial_entries_count + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix that you did prevent log entry creation in case of pk is None, why did the log entry count increased by one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New entry has been created because we duplicated obj which is expected behavior. auditlog currently thinks that we're updating the object which is why it crashes on IntegrityError.
|
Thanks @kubajecminek for the fix. I do not entirely understand the problem. could you please provide more information like error trace back? Also, please add an entry to changelog file. |
|
Thanks for the review.
Sure. You can copy/duplicate object in Django with this trick: However Here's sample backtrace from running the tests without the fix:
Will do! |
|
Thanks @kubajecminek |
Hi, thank you for
auditlog.This pull request fixes bug number #664. It is naive implementation but it seems that it works as expected. Please let me know what you think so I can adjust the patch accordingly.