Wednesday, October 22, 2014

Re: AppConfig where to execute initialization queries?

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?

Although you can access model classes as described above, avoid interacting with the database in your ready()implementation. This includes model methods that execute queries (save()delete(), manager methods etc.), and also raw SQL queries via django.db.connection. Your 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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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.

No comments:

Post a Comment