Permalink
Browse files

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

  • Loading branch information...
1 parent e2b6e22 commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01 @freakboy3742 freakboy3742 committed Sep 23, 2012
Showing with 18 additions and 2 deletions.
  1. +8 −2 django/db/backends/__init__.py
  2. +10 −0 tests/modeltests/proxy_models/tests.py
@@ -319,6 +319,7 @@ def cursor(self):
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 @@ def sequence_reset_sql(self, style, model_list):
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 @@ def combine_expression(self, connector, sub_expressions):
conn = ' %s ' % connector
return conn.join(sub_expressions)
+
class BaseDatabaseIntrospection(object):
"""
This class encapsulates all backend-specific introspection utilities
@@ -1010,12 +1012,14 @@ def sequence_list(self):
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 @@ def get_indexes(self, cursor, table_name):
"""
raise NotImplementedError
+
class BaseDatabaseClient(object):
"""
This class encapsulates all backend-specific methods for opening a
@@ -1068,6 +1073,7 @@ def __init__(self, connection):
def runshell(self):
raise NotImplementedError()
+
class BaseDatabaseValidation(object):
"""
This class encapsualtes all backend-specific model validation.
@@ -1,11 +1,13 @@
from __future__ import absolute_import, unicode_literals
+import copy
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
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 Meta:
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 Meta:
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")

0 comments on commit 8a527dd

Please sign in to comment.