Branch: refs/heads/master
  Home:   https://github.com/django/django
  Commit: 4fdd378beb81a86d826d7ee83c7d2250ed958be1
      
https://github.com/django/django/commit/4fdd378beb81a86d826d7ee83c7d2250ed958be1
  Author: Anssi Kääriäinen <akaar...@gmail.com>
  Date:   2012-04-30 (Mon, 30 Apr 2012)

  Changed paths:
    M django/core/management/base.py
    M django/core/management/commands/syncdb.py
    M django/test/testcases.py

  Log Message:
  -----------
  Skip model validation when models are known good.

In some situations Django calls model validation when the models are
already known good. This is most visible in tests, which use flush
and loaddata commands. This resulted in around 10% overhead when
running tests under sqlite.


diff --git a/django/core/management/base.py b/django/core/management/base.py
index 2a04c25..a936877 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -198,9 +198,9 @@ def execute(self, *args, **options):
         """
         Try to execute this command, performing model validation if
         needed (as controlled by the attribute
-        ``self.requires_model_validation``). If the command raises a
-        ``CommandError``, intercept it and print it sensibly to
-        stderr.
+        ``self.requires_model_validation``, except if force-skipped). If the
+        command raises a ``CommandError``, intercept it and print it sensibly
+        to stderr.
         """
         show_traceback = options.get('traceback', False)
 
@@ -226,7 +226,7 @@ def execute(self, *args, **options):
         try:
             self.stdout = options.get('stdout', sys.stdout)
             self.stderr = options.get('stderr', sys.stderr)
-            if self.requires_model_validation:
+            if self.requires_model_validation and not 
options.get('skip_validation'):
                 self.validate()
             output = self.handle(*args, **options)
             if output:
diff --git a/django/core/management/commands/syncdb.py 
b/django/core/management/commands/syncdb.py
index 91f0aec..88caea1 100644
--- a/django/core/management/commands/syncdb.py
+++ b/django/core/management/commands/syncdb.py
@@ -160,4 +160,5 @@ def model_installed(model):
         # Load initial_data fixtures (unless that has been disabled)
         if load_initial_data:
             from django.core.management import call_command
-            call_command('loaddata', 'initial_data', verbosity=verbosity, 
database=db)
+            call_command('loaddata', 'initial_data', verbosity=verbosity,
+                         database=db, skip_validation=True)
diff --git a/django/test/testcases.py b/django/test/testcases.py
index c9fe1b3..e2d7b3f 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -468,13 +468,14 @@ def _fixture_setup(self):
         else:
             databases = [DEFAULT_DB_ALIAS]
         for db in databases:
-            call_command('flush', verbosity=0, interactive=False, database=db)
+            call_command('flush', verbosity=0, interactive=False, database=db,
+                         skip_validation=True)
 
             if hasattr(self, 'fixtures'):
                 # We have to use this slightly awkward syntax due to the fact
                 # that we're using *args and **kwargs together.
                 call_command('loaddata', *self.fixtures,
-                             **{'verbosity': 0, 'database': db})
+                             **{'verbosity': 0, 'database': db, 
'skip_validation': True})
 
     def _urlconf_setup(self):
         if hasattr(self, 'urls'):
@@ -826,7 +827,8 @@ def _fixture_setup(self):
                              **{
                                 'verbosity': 0,
                                 'commit': False,
-                                'database': db
+                                'database': db,
+                                'skip_validation': True,
                              })
 
     def _fixture_teardown(self):


================================================================

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to