0
0
mirror of https://github.com/django/django.git synced 2024-11-29 22:56:46 +01:00

Ensure sequences are reset correctly in the presence of swapped models.

This commit is contained in:
Russell Keith-Magee 2012-09-24 07:48:05 +08:00
parent e2b6e22f29
commit 8a527dda13
2 changed files with 18 additions and 2 deletions

View File

@ -319,6 +319,7 @@ class BaseDatabaseWrapper(object):
def make_debug_cursor(self, cursor):
return util.CursorDebugWrapper(cursor, self)
class BaseDatabaseFeatures(object):
allows_group_by_pk = False
# True if django.db.backend.utils.typecast_timestamp is used on values
@ -776,7 +777,7 @@ class BaseDatabaseOperations(object):
The `style` argument is a Style object as returned by either
color_style() or no_style() in django.core.management.color.
"""
return [] # No sequence reset required by default.
return [] # No sequence reset required by default.
def start_transaction_sql(self):
"""
@ -915,6 +916,7 @@ class BaseDatabaseOperations(object):
conn = ' %s ' % connector
return conn.join(sub_expressions)
class BaseDatabaseIntrospection(object):
"""
This class encapsulates all backend-specific introspection utilities
@ -1010,12 +1012,14 @@ class BaseDatabaseIntrospection(object):
for model in models.get_models(app):
if not model._meta.managed:
continue
if model._meta.swapped:
continue
if not router.allow_syncdb(self.connection.alias, model):
continue
for f in model._meta.local_fields:
if isinstance(f, models.AutoField):
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
break # Only one AutoField is allowed per model, so don't bother continuing.
break # Only one AutoField is allowed per model, so don't bother continuing.
for f in model._meta.local_many_to_many:
# If this is an m2m using an intermediate table,
@ -1052,6 +1056,7 @@ class BaseDatabaseIntrospection(object):
"""
raise NotImplementedError
class BaseDatabaseClient(object):
"""
This class encapsulates all backend-specific methods for opening a
@ -1068,6 +1073,7 @@ class BaseDatabaseClient(object):
def runshell(self):
raise NotImplementedError()
class BaseDatabaseValidation(object):
"""
This class encapsualtes all backend-specific model validation.

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import, unicode_literals
import copy
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
@ -6,6 +7,7 @@ from django.core import management
from django.core.exceptions import FieldError
from django.db import models, DEFAULT_DB_ALIAS
from django.db.models import signals
from django.db.models.loading import cache
from django.test import TestCase
@ -147,6 +149,12 @@ class ProxyModelTests(TestCase):
def test_swappable(self):
try:
# This test adds dummy applications to the app cache. These
# need to be removed in order to prevent bad interactions
# with the flush operation in other tests.
old_app_models = copy.deepcopy(cache.app_models)
old_app_store = copy.deepcopy(cache.app_store)
settings.TEST_SWAPPABLE_MODEL = 'proxy_models.AlternateModel'
class SwappableModel(models.Model):
@ -165,6 +173,8 @@ class ProxyModelTests(TestCase):
proxy = True
finally:
del settings.TEST_SWAPPABLE_MODEL
cache.app_models = old_app_models
cache.app_store = old_app_store
def test_myperson_manager(self):
Person.objects.create(name="fred")