Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration chicken-egg problem #29

Open
stefanfoulis opened this issue Jul 11, 2016 · 4 comments
Open

migration chicken-egg problem #29

stefanfoulis opened this issue Jul 11, 2016 · 4 comments

Comments

@stefanfoulis
Copy link

Can't run python manage.py migrate on a fresh database, because multisite.template.loaders.filesystem causes a db query to the django_site table.

@stefanfoulis
Copy link
Author

The workaround is of course to remove the template loader at initial migration time. But in some automated environments that is tedious.

IMHO no db queries or cache access should happen at import time.

@jedie
Copy link

jedie commented Jul 15, 2016

I get the same problem :(

But removing the template loader will not help here.

@mghughes
Copy link

mghughes commented Aug 3, 2016

I can't seem to reproduce this problem - using a fresh django 1.9 project with django-multisite 1.3.1 and these settings: https://gist.github.com/mghughes/6710f72d5c6ad6ffb6e4c9857ced7fe3

Since there are multiple people with this problem, am I missing something obvious? Or can you provide more information about what you're doing differently?

@JordanReiter
Copy link

Stepping in because I've run across this error now.

This error can occur if you use an app which attempts to load a template on startup. I'm not sure how many apps do this regularly, but one prominent one is django-cms. It happens when it calls setup() in its apps.py file. This in turn calls plugin_pool.validate_templates() which calls loader.get_template().

There is no way to prevent this error from occurring as far as I can tell. I've looked at all of the involved code and apart from setting django-cms to catch all exceptions in its validate_templates method there isn't a way of preventing the error.

Obviously, this means that doing a standard test which starts with a completely empty database will not work unless you disable multisite during testing.

One possibility is something like this (untested):

# settings.py
_, command = sys.argv[:2]
if command in ['test', 'migrate']:
    ORIGINAL_TEMPLATES = list(TEMPLATES)
    TEMPLATES[0]['loaders'].remove('multisite.template_loader.Loader')

And then, in a test file:

from django.conf import settings

class TestMultiSiteLayouts(TestCase):
    def test_something:
        with self.override_settings(TEMPLATES=list(settings.ORIGINAL_TEMPLATES)):
            … do tests for multisite here …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants