diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-07-30 02:42:36 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-07-30 02:42:36 +0000 |
| commit | bab9aab9a2cd82706e2a15044db40b9fc85afbc5 (patch) | |
| tree | 545aac0da4eafaa34d94ff4560f8efc6fd213398 /tests | |
| parent | cd8758ef4dd28f55858d1df65bf5d4ce07137eb1 (diff) | |
Fixed #13941 -- Corrected the way sequence names are reset under Postgres, especially when generic foreign keys are involved. Thanks to Ales Zoulek for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13449 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/backends/models.py | 15 | ||||
| -rw-r--r-- | tests/regressiontests/backends/tests.py | 19 |
2 files changed, 33 insertions, 1 deletions
diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py index e3137f2710..d6ca81e113 100644 --- a/tests/regressiontests/backends/models.py +++ b/tests/regressiontests/backends/models.py @@ -1,3 +1,5 @@ +from django.contrib.contenttypes import generic +from django.contrib.contenttypes.models import ContentType from django.conf import settings from django.db import models from django.db import connection, DEFAULT_DB_ALIAS @@ -37,6 +39,19 @@ if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql': m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.ManyToManyField(Person,blank=True) +class Tag(models.Model): + name = models.CharField(max_length=30) + content_type = models.ForeignKey(ContentType) + object_id = models.PositiveIntegerField() + content_object = generic.GenericForeignKey('content_type', 'object_id') + + +class Post(models.Model): + name = models.CharField(max_length=30) + text = models.TextField() + tags = generic.GenericRelation('Tag') + + qn = connection.ops.quote_name __test__ = {'API_TESTS': """ diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py index ee3ccdc72f..19d7fc5f6c 100644 --- a/tests/regressiontests/backends/tests.py +++ b/tests/regressiontests/backends/tests.py @@ -6,7 +6,7 @@ import unittest from django.conf import settings from django.core import management from django.core.management.color import no_style -from django.db import backend, connection, DEFAULT_DB_ALIAS +from django.db import backend, connection, connections, DEFAULT_DB_ALIAS from django.db.backends.signals import connection_created from django.test import TestCase @@ -137,6 +137,23 @@ if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql': for statement in connection.ops.sql_flush(no_style(), tables, sequences): cursor.execute(statement) +class SequenceResetTest(TestCase): + def test_generic_relation(self): + "Sequence names are correct when resetting generic relations (Ref #13941)" + # Create an object with a manually specified PK + models.Post.objects.create(id=10, name='1st post', text='hello world') + + # Reset the sequences for the database + cursor = connection.cursor() + commands = connections[DEFAULT_DB_ALIAS].ops.sequence_reset_sql(no_style(), [models.Post]) + for sql in commands: + cursor.execute(sql) + + # If we create a new object now, it should have a PK greater + # than the PK we specified manually. + obj = models.Post.objects.create(name='New post', text='goodbye world') + self.assertTrue(obj.pk > 10) + def connection_created_test(sender, **kwargs): print 'connection_created signal' |
