Opened 6 years ago
Closed 6 years ago
#29559 closed Bug (fixed)
TransactionTestCase.reset_sequences doesn't reset sequences of auto created ManyToMany models
Reported by: | Oliver Sauder | Owned by: | Oliver Sauder |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Consider following example:
class Person(models.Model): first_name = models.CharField(max_length=20) last_name = models.CharField(max_length=20) friends = models.ManyToManyField('self') class AutoIncrementResetTest(TransactionTestCase): reset_sequences = True def test_autoincrement_reset1(self): p = Person.objects.create(first_name='Jack', last_name='Smith') self.assertEqual(p.pk, 1) p.friends.add(Person.objects.create(first_name='Jacky', last_name='Smith')) self.assertEqual(p.friends.through.objects.first().pk, 1) def test_autoincrement_reset2(self): p = Person.objects.create(first_name='Jack', last_name='Smith') self.assertEqual(p.pk, 1) p.friends.add(Person.objects.create(first_name='Jacky', last_name='Smith')) self.assertEqual(p.friends.through.objects.first().pk, 1)
Test test_autoincrement_reset2 will fail with a much higher primary key, indicating that sequence has not been properly reset. Tested this on a Postgres database but I assume this error exist on other databases as well.
Change History (4)
comment:1 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 6 years ago
Has patch: | set |
---|
comment:3 by , 6 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
PR