summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2011-01-18 16:43:01 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2011-01-18 16:43:01 +0000
commitb31a1b99261d05bf8a34495ee9faf4d6592b8b36 (patch)
treef4064ac0d7e287596458823a67e7f75ea0ddd444 /docs
parent5502fa59801c70094b6a2e789ece65aa7b31b58c (diff)
Refs #14661 -- Clarified the handling of initial data injected via custom SQL.
This is BACKWARDS INCOMPATIBLE CHANGE for anyone relying on SQL-injected initial data in a test case. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15239 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/howto/initial-data.txt11
-rw-r--r--docs/releases/1.3.txt30
-rw-r--r--docs/topics/testing.txt9
3 files changed, 50 insertions, 0 deletions
diff --git a/docs/howto/initial-data.txt b/docs/howto/initial-data.txt
index cf3f65d299..dd6a099b9d 100644
--- a/docs/howto/initial-data.txt
+++ b/docs/howto/initial-data.txt
@@ -121,6 +121,17 @@ the order in which they're executed. The only thing you can assume is
that, by the time your custom data files are executed, all the
database tables already will have been created.
+.. admonition:: Initial SQL data and testing
+
+ This technique *cannot* be used to provide initial data for
+ testing purposes. Django's test framework flushes the contents of
+ the test database after each test; as a result, any data added
+ using the custom SQL hook will be lost.
+
+ If you require data for a test case, you should add it using
+ either a :ref:`test fixture <topics-testing-fixtures>`, or
+ programatically add it during the ``setUp()`` of your test case.
+
Database-backend-specific SQL data
----------------------------------
diff --git a/docs/releases/1.3.txt b/docs/releases/1.3.txt
index d41dc8630c..1904e9526d 100644
--- a/docs/releases/1.3.txt
+++ b/docs/releases/1.3.txt
@@ -410,6 +410,36 @@ Bloggs'``. Although the previous behaviour was not useful for a template languag
designed for web designers, and was never deliberately supported, it is possible
that some templates may be broken by this change.
+Use of custom SQL to load initial data in tests
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Django provides a custom SQL hooks as a way to inject hand-crafted SQL
+into the database synchronization process. One of the possible uses
+for this custom SQL is to insert data into your database. If your
+custom SQL contains ``INSERT`` statements, those insertions will be
+performed every time your database is synchronized. This includes the
+synchronization of any test databases that are created when you run a
+test suite.
+
+However, in the process of testing the Django 1.3, it was discovered
+that this feature has never completely worked as advertised. When
+using database backends that don't support transactions, or when using
+a TransactionTestCase, data that has been inserted using custom SQL
+will not be visible during the testing process.
+
+Unfortunately, there was no way to rectify this problem without
+introducing a backwards incompatibility. Rather than leave
+SQL-inserted initial data in an uncertain state, Django now enforces
+the policy that data inserted by custom SQL will *not* be visible
+during testing.
+
+This change only affects the testing process. You can still use custom
+SQL to load data into your production database as part of the syncdb
+process. If you require data to exist during test conditions, you
+should either insert it using :ref:`test fixtures
+<topics-testing-fixtures>`, or using the ``setUp()`` method of your
+test case.
+
.. _deprecated-features-1.3:
Features deprecated in 1.3
diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
index 78590ddb2b..795f041fb9 100644
--- a/docs/topics/testing.txt
+++ b/docs/topics/testing.txt
@@ -1237,6 +1237,15 @@ documentation<dumpdata>` for more details.
Fixtures with other names can always be installed manually using
the :djadmin:`manage.py loaddata<loaddata>` command.
+.. admonition:: Initial SQL data and testing
+
+ Django provides a second way to insert initial data into models --
+ the :ref:`custom SQL hook <initial-sql>`. However, this technique
+ *cannot* be used to provide initial data for testing purposes.
+ Django's test framework flushes the contents of the test database
+ after each test; as a result, any data added using the custom SQL
+ hook will be lost.
+
Once you've created a fixture and placed it in a ``fixtures`` directory in one
of your :setting:`INSTALLED_APPS`, you can use it in your unit tests by
specifying a ``fixtures`` class attribute on your :class:`django.test.TestCase`