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

Site does not exist during migrations for sharedcontent plugin. #55

Open
mrmachine opened this issue Sep 2, 2015 · 4 comments
Open

Comments

@mrmachine
Copy link
Contributor

During migrations, Django tries to evaluate the default value for the site field in order to create the model.

The default is a callable that returns Site.objects.get_current().pk. On a fresh database, no Site object exists.

If django-fluent-pages is also installed, its migrations will actually create a default Site object if none exist. But when django-fluent-contents is used on its own, this doesn't happen.

Perhaps the make_site code from django-fluent-pages should be abstracted into django-fluent-utils and called by fluent_contents.plugins.sharedcontent.utils.get_current_site_id()?

See: https://github.com/edoburu/django-fluent-pages/blob/master/fluent_pages/migrations/0001_initial.py#L10

@sjdines
Copy link

sjdines commented Sep 2, 2015

If you are going down that path why not put get_current_side_id() into django-fluent-utils as well?

Should the get_current_site_id() enforce a site to be there or should it be just in the migration to call make_site where appropriate?

Another option maybe to to register the call against a pre_migrate signal?

@mrmachine
Copy link
Contributor Author

Or just move the make_site function into django-fluent-utils and add a data migration to the top of the operations list in fluent_contents.plugins.sharedcontent.migrations.0001_initial?

It's a data migration that only creates a default site if one doesn't already exist, so it should be safe to add this into an existing migration without damaging existing installations?

Then fluent-contents will behave the same as fluent-pages and we don't need to touch the get_* methods which may be called by other code.

@mrmachine
Copy link
Contributor Author

FYI, I have worked around this in my project by adding a new migration that duplicates the make_site data migration from django-fluent-pages and adds a reverse dependency:

    run_before = [
        ('sharedcontent', '0001_initial'),
    ]

@vdboor
Copy link
Contributor

vdboor commented Oct 7, 2015

Good points! Sorry for not replying earlier (due to holidays).
I'm all for placing this feature into django-fluent-utils. I didn't notice it before as all my projects use django-fluent-pages. From what I see, everything can be placed in fluent-utils:

  • The migration action to create a default site, named as CreateInitialSite?
  • The get_current_site_id() code
  • All of sharedcontent.utils

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

3 participants