Testsuite error when django.contrib.sites is not enabled #6

sindresorhus opened this Issue Jun 14, 2011 · 3 comments


None yet

2 participants


The testsuite throws an error if the django.contrib.sites is not added to the project.

ERROR: test_urls (newsletter.tests.test_web.WebUserSubscribeTestCase)
Traceback (most recent call last):
  File "/Users/sindresorhus/Dropbox/Job/django_sandbox/newsletter/tests/test_web.py", line 171, in setUp
    self.n.site = get_default_sites()
  File "/Users/sindresorhus/Dropbox/Job/django_sandbox/newsletter/models.py", line 30, in get_default_sites
    return [site.id for site in Site.objects.all()]
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 107, in _result_iter
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 772, in _fill_cache
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 273, in iterator
    for row in compiler.results_iter():
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 234, in execute
    return Database.Cursor.execute(self, query, params)
DatabaseError: no such table: django_site

In my opinion "sites" should be optional, and the code should check for the existence for "sites" instead of assuming it's there.


It should be optional, but currently is not. I propose the following:

  • You are welcome to update the code such that it only loosely couples into the Django sites module. Probably the easiest way to accomplish this is to add a setting which automatically evaluates to True if the sites module is in INSTALLED_APPS. When your patch is done, give me a pull request and after a small code review I'll merge it into the master branch.
  • Meanwhile, I will add a small note about the current requirement of the sites module in the documentation until your code is merged into the master branch.

In other words: fork me!


Have added the requirement to the documentation, as well as to INSTALLED_APPS in test_settings.py. I will consider this issue to be closed for now.

@dokterbob dokterbob closed this Oct 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment