diff options
| author | Zbigniew Siciarz <antyqjon@gmail.com> | 2014-02-15 17:27:12 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-02-15 13:50:31 -0500 |
| commit | 94b5bc361aef2ae2d46a49dbfe32d9271c185800 (patch) | |
| tree | 1c1dd3985203cde057b970832b3c2b2572630ff0 | |
| parent | cd7f37b6471dc947f06a40149e6c9789531e50a0 (diff) | |
Fixed #22002 -- Documented avoiding database interaction in AppConfig.ready().
Thanks Marc Tamlyn for the suggestion.
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | docs/ref/applications.txt | 13 | ||||
| -rw-r--r-- | docs/topics/testing/overview.txt | 5 |
3 files changed, 19 insertions, 0 deletions
@@ -561,6 +561,7 @@ answer newbie questions, and generally made Django that much better: Peter Sheats <sheats@gmail.com> Pete Shinners <pete@shinners.org> Leo Shklovskii + Zbigniew Siciarz <zbigniew@siciarz.net> jason.sidabras@gmail.com MikoĊaj Siedlarek <mikolaj.siedlarek@gmail.com> Karol Sikora <elektrrrus@gmail.com> diff --git a/docs/ref/applications.txt b/docs/ref/applications.txt index be86f42305..2a5128ebb8 100644 --- a/docs/ref/applications.txt +++ b/docs/ref/applications.txt @@ -221,6 +221,19 @@ Methods def ready(self): MyModel = self.get_model('MyModel') + .. warning:: + + Although you can access model classes as described above, avoid + interacting with the database in your :meth:`ready()` implementation. + This includes model methods that execute queries + (:meth:`~django.db.models.Model.save()`, + :meth:`~django.db.models.Model.delete()`, manager methods etc.), and + also raw SQL queries via ``django.db.connection``. Your + :meth:`ready()` method will run during startup of every management + command. For example, even though the test database configuration is + separate from the production settings, ``manage.py test`` would still + execute some queries against your **production** database! + .. _namespace package: Namespace packages as apps (Python 3.3+) diff --git a/docs/topics/testing/overview.txt b/docs/topics/testing/overview.txt index 078c2a1da9..7a2d15edce 100644 --- a/docs/topics/testing/overview.txt +++ b/docs/topics/testing/overview.txt @@ -196,6 +196,11 @@ advanced settings. your tests. *It is a bad idea to have such import-time database queries in your code* anyway - rewrite your code so that it doesn't do this. + .. versionadded:: 1.7 + + This also applies to customized implementations of + :meth:`~django.apps.AppConfig.ready()`. + .. seealso:: The :ref:`advanced multi-db testing topics <topics-testing-advanced-multidb>`. |
