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

Make sites optional #119

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

tisdall
Copy link

@tisdall tisdall commented Mar 30, 2017

As mentioned in #15, this change is to continue supporting the "sites" framework, but also make it work without it so it's now optional.

NOTE:

  • there's one translatable string added (I wanted to retain the existing string so existing translations would continue working. The new string is the same but with the URL and linefeeds removed.)
  • tests haven't been changed to test for running with no SITE_ID or sites framework installed. Should all the tests be run twice, once with sites and once without?

@tisdall
Copy link
Author

tisdall commented Mar 30, 2017

hmm... I'm not that familiar with test runner.. I didn't make changes to the tests so I thought they'd continue to work, but the Travis errors indicate it's having issues setting up the DB. ValueError: Related model u'sites.Site' cannot be resolved Shouldn't that have been resolved by the list of installed apps?

@@ -8,7 +8,6 @@
class Migration(migrations.Migration):

dependencies = [
('sites', '0001_initial'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot simply remove that line, because later in that migration, you have a reference to sites.Site which won't resolve with this removal. I can imagine various scenarios to workaround this:

  • just make the Site fk nullable without removing the contrib.sites requirement.
  • replace the sites.Site by some sort of placeholder which will either import the Site model if contrib.sites is installed or replace it by some fake model otherwise. Not sure if it is feasible.
    Sorry, it's probably harder than it appears, but worth a try.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're creating a migration for a model that uses another model that has no migrations, shouldn't you be able to do that without requiring a '0001_initial' from that other object (since it doesn't exist)? However, even if it ran without that migration dependency, the 'sites' would still need to be installed for that ForeignKey to be created (forgot about that).

Okay, I guess I'll have to re-think this a bit. The "placeholder" seems like a good idea but if someone ever turned sites on/off after installing this package they'd likely get some confusing errors.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an extension of ForeignKey would be needed. One that could handle 'sites' being turned on/off or possibly give a descriptive warning if 'sites' is turned on/off without changing the database properly.

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

Successfully merging this pull request may close these issues.

2 participants