Did you find a good solution for this? On Monday, October 6, 2014 11:56:15 PM UTC+11, Marc Aymerich wrote: > > Hi, > I have been bitten by unexpected behaviors when running tests because on > AppConfig.ready() I was initializing some stuff that depends on DB stored > data. Reading the django docs I've found a warning that specifically > suggests not to do this [1]. But then I wonder where this kind of > initialization logic should go? any suggestion? > > [1] > https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig.ready > > Although you can access model classes as described above, avoid > interacting with the database in your ready() > <https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig.ready>implementation. > > This includes model methods that execute queries (save() > <https://docs.djangoproject.com/en/1.7/ref/models/instances/#django.db.models.Model.save> > , delete() > <https://docs.djangoproject.com/en/1.7/ref/models/instances/#django.db.models.Model.delete>, > > manager methods etc.), and also raw SQL queries via django.db.connection. > Your ready() > <https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig.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! > > -- > Marc >
-- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/adb815d6-f63f-4bc8-981b-de38a273739f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

