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

Zinnia breaks on Django 1.7b1: get_user_model at init time #342

Closed
delroth opened this issue Apr 18, 2014 · 49 comments
Closed

Zinnia breaks on Django 1.7b1: get_user_model at init time #342

delroth opened this issue Apr 18, 2014 · 49 comments

Comments

@delroth
Copy link

delroth commented Apr 18, 2014

zinnia.models.author.Author uses get_user_model() at module import time, which is forbidden by Django 1.7 (https://docs.djangoproject.com/en/dev/releases/1.7/#app-loading-refactor). 1.7 is due for release soon (beta has been released), so a way to avoid this import time dependency should be figured out.

@Fantomas42
Copy link
Owner

This issue is now on top of the TODO.

I never develop against beta release.

Pull Request are welcome.

@hriechmann
Copy link

Hi,
The fix does not work for me (Python 3.3.5, Django 1.7b4).
python manage.py migrate gives:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/root/django-test/django-root/lib/python3.3/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/root/django-test/django-root/lib/python3.3/site-packages/django/core/management/__init__.py", line 391, in execute
    django.setup()
  File "/root/django-test/django-root/lib/python3.3/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/root/django-test/django-root/lib/python3.3/site-packages/django/apps/registry.py", line 106, in populate
    app_config.import_models(all_models)
  File "/root/django-test/django-root/lib/python3.3/site-packages/django/apps/config.py", line 190, in import_models
    self.models_module = import_module(models_module_name)
  File "/root/django-test/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/root/django-test/django-root/lib/python3.3/site-packages/zinnia/models/__init__.py", line 3, in <module>
    from zinnia.models.author import Author
  File "/root/django-test/django-root/lib/python3.3/site-packages/zinnia/models/author.py", line 27, in <module>
    AuthorPublishedManager):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

settings.AUTH_USER_MODEL seems to be a str, thus it cannot be used as a baseclass.
From the docs I would assume that django handles class names as string correctly for model relations, but in this case this does not help.

As a workaround I derived Author from django.contrib.auth.models.User, but this will break if settings.AUTH_USER_MODEL was changed at a site.

From https://docs.djangoproject.com/en/dev/topics/auth/customizing/ I would assume that the preferred way would be to use a OneToOneField from Author to User:

If you wish to store information related to User, you can use a one-to-one relationship
to a model containing the fields for additional information. This one-to-one model
is often called a profile model, as it might store non-auth related information
about a site user. 

@benvand
Copy link

benvand commented May 27, 2014

Sorry thought I had removed this. I will try and post some notes on what I
found later today.
On 27 May 2014 09:15, "hriechmann" notifications@github.com wrote:

Hi,
The fix does not work for me (Python 3.3.5, Django 1.7b4).
python manage.py migrate gives:

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/root/django-test/django-root/lib/python3.3/site-packages/django/core/management/init.py", line 427, in execute_from_command_line
utility.execute()
File "/root/django-test/django-root/lib/python3.3/site-packages/django/core/management/init.py", line 391, in execute
django.setup()
File "/root/django-test/django-root/lib/python3.3/site-packages/django/init.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/root/django-test/django-root/lib/python3.3/site-packages/django/apps/registry.py", line 106, in populate
app_config.import_models(all_models)
File "/root/django-test/django-root/lib/python3.3/site-packages/django/apps/config.py", line 190, in import_models
self.models_module = import_module(models_module_name)
File "/root/django-test/lib/python3.3/importlib/init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1584, in _gcd_import
File "", line 1565, in _find_and_load
File "", line 1532, in _find_and_load_unlocked
File "", line 584, in _check_name_wrapper
File "", line 1022, in load_module
File "", line 1003, in load_module
File "", line 560, in module_for_loader_wrapper
File "", line 868, in _load_module
File "", line 313, in _call_with_frames_removed
File "/root/django-test/django-root/lib/python3.3/site-packages/zinnia/models/init.py", line 3, in
from zinnia.models.author import Author
File "/root/django-test/django-root/lib/python3.3/site-packages/zinnia/models/author.py", line 27, in
AuthorPublishedManager):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

settings.AUTH_USER_MODEL seems to be a str, thus it cannot be used as a
baseclass.
From the docs I would assume that django handles class names as string
correctly for model relations, but in this case this does not help.

As a workaround I derived Author from django.contrib.auth.models.User, but
this will break if settings.AUTH_USER_MODEL was changed at a site.

From https://docs.djangoproject.com/en/dev/topics/auth/customizing/ I
would assume that the preferred way would be to use a OneToOneField from
Author to User:

If you wish to store information related to User, you can use a one-to-one relationship
to a model containing the fields for additional information. This one-to-one model
is often called a profile model, as it might store non-auth related information
about a site user.


Reply to this email directly or view it on GitHubhttps://github.com//issues/342#issuecomment-44246731
.

sergeny added a commit to Magnatelabs/django-blog-zinnia that referenced this issue Jun 21, 2014
@aisayko
Copy link

aisayko commented Sep 3, 2014

Django 1.7 is released. Issue become critical.

@Fantomas42
Copy link
Owner

@aisayko Yes I have seen the release this morning.
Critical, critical, this a such a big word. Everybody will not jump to Django 1.7 tomorrow.
The issue will be fixed when I have time to spend on this point, or when somebody will make a functional pull request.

@benvand
Copy link

benvand commented Sep 4, 2014

Whilst I agree that there is time to fix this issue before the majority of
people start wanting to use Zinnia with 1.7 I'd also say that having looked
at the problem it is, as far as I can tell, non-trivial.

I think the crux of the matter is that it isn't possible to create a proxy
model on the AUTH_USER_MODEL any more. This is because we have to wait for
the model registry to complete its collation of the projects models before
we can call get_app on the registry. This is the method used by
get_user_model to get the user model.

The proxy model needs to be registered as part of the registry but can't be
registered until the registry is complete because we need to use
get_user_model / get_app. Catch 22.

On Wed, Sep 3, 2014 at 1:20 PM, Julien Fache notifications@github.com
wrote:

@aisayko https://github.com/aisayko Yes I have seen the release this
morning.
Critical, critical, this a such a big word. Everybody will not jump to
Django 1.7 tomorrow.
The issue will be fixed when I have time to spend on this point, or when
somebody will make a functional pull request.


Reply to this email directly or view it on GitHub
#342 (comment)
.

@Fantomas42
Copy link
Owner

@benvand I'm perfectly okay with you on all the points.

@ivanvenosdel
Copy link

From https://docs.djangoproject.com/en/dev/topics/auth/customizing/ I would assume that the preferred way would be to use a OneToOneField from Author to User:

If you wish to store information related to User, you can use a one-to-one relationship
to a model containing the fields for additional information. This one-to-one model
is often called a profile model, as it might store non-auth related information
about a site user.

@benvand, @hriechmann I think this is a good way to go about it. In addition to adding 1.7 compatibility, doing away with a proxy model will address #369 and will likely make #346 easier to deal with. Also it just makes more sense to me from a design perspective. My settings.AUTH_USER_MODEL is my user model. My site may have a site profile model attached to it and Zinnia has a blog profile (Author) attached to it. From a user perspective I would have a profile for the site and another profile for the blog.

With this foundation in place the Zinnia profile (Author) could be done in such a way that a Zinnia implementer could extend/customize aspects of the Author model. E.g. Make its display fields return information from their site's profile.

@benvand
Copy link

benvand commented Sep 16, 2014

So my thinking was you could create the same functionality with a post save signal on the settings.AUTH_USER_MODEL that automatically creates a:

class Author(models.Model)
    user = models.OneToOneField(settings.AUTH_USER_MODEL) 
    etc...
    etc...

but you can't register signals with AUTH_USER_MODEL because you register signals at run time too.

Just spitballing here but I suppose you could replace every instance of:

    Author.objects.get(pk=request.user.id)  

with an

    Author.objects.get_or_create(id=request.user.id, user=get_user_model().objects.get(id=request.user.id))[0]  

Something like that?

@ivanvenosdel
Copy link

Author.objects.get_or_create(id=request.user.id, user=get_user_model().objects.get(id=request.user.id))[0]

Couldn't this be as simple as Author.objects.get_or_create(user=request.user)[0]?

I don't think it's a good idea to assume that the author id is in sync with the user id as all kinds of scenarios can prevent that from being the case. It seems safe to me to be able to just assume user=request.user is unique because that relationship should be a one to one.

Edit Note: I realize now that you may be assuming they are the same because it might be what the code does now. I think I need to research this a bit more.

Edit Note 2: It's ok for the code to assume it now as it's a proxy model and an Author does not maintain it's own record. Whereas in the case of a foreign key it would maintain it's own record (because Author would become a non-proxy, standard model). So I guess my initial concern about assuming the author and user id is the same is accurate (if the Author would no longer be a proxy).

@benvand
Copy link

benvand commented Sep 17, 2014

I think this may work. You're right about the id of author objects not mattering. Proxy model.
I'm not sure when I'd be able to take a run at this. Busy week and PyConUK this weekend. If anyone else wants it then go for it. Otherwise I might get some time towards the end of the month.

For posterity what we need to do is replace the proxy model models.author.Author with a standard model that whilst containing all the functionality of the proxy model also has a one-to-one relationship with settings.AUTH_USER_MODEL.

class Author(models.Model)
    user = models.OneToOneField(settings.AUTH_USER_MODEL) 
    etc...
    etc...

In the codebase we need to reflect this refactor accessing the author model specifically using

author = Author.objects.get_or_create(user=request.user)[0]

and not using (for example)

request.user.author

unless a DoesNotExist try except is implemented

@ivanvenosdel @Fantomas42 does that sound about right to everyone?

@ivanvenosdel
Copy link

Sounds good to me. I am going to take a shot at it today.

ivanvenosdel added a commit to WimpyAnalytics/django-blog-zinnia that referenced this issue Sep 22, 2014
…test file (zinnia.tests.test_feeds) passing.
ivanvenosdel added a commit to WimpyAnalytics/django-blog-zinnia that referenced this issue Sep 22, 2014
@ivanvenosdel
Copy link

Once I got started I found that it will be a lot more work then I have time for but I did figure out a few things that should be useful.

Here are my initial steps, I had replaced the proxy model with a concrete one and managed to fix a few test files but stopped when I realized the amount of effort involved will be large to say the least.
https://github.com/WimpyAnalytics/django-blog-zinnia/tree/17support342

The most important thing I noticed is that changes for the proxy-to-concrete-model approach will have to be made before Zinnia can upgrade to 1.7. This is because the 1.7 migrations won't even initialize until this issue is first addressed.

The concrete model path as I see it: Zinnia will actually have to release two versions, one that will make the DB of those using Zinnia ready for 1.7 and a second that actually supports 1.7.

For example, the work involved in each release could be.

Final 1.6 release:

  1. Upgrade South to 1.0 and move the migrations to a folder called 'south_migrations' which 1.0 knows to look for.
  2. Replace proxy Author with concrete Author that links to user
  3. Create the south migration for it.
  4. Update code to support new Concrete Author model.

1.7 Friendly Release:

  1. Moving from south to built-in migrations (this effectively starts migrations over in a 'migrations' folder as before)
  2. Addressing any other backward incompatible changes
  3. Addressing any deprecations

A site that uses Zinnia would first have to upgrade to Zinnia's final 1.6 version, applying it's migrations. Then when it's ready to go to 1.7 it would have to upgrade to Zinnia's 1.7 friendly version.

Edit: Removed some inaccurate compatibility notes.

@Fantomas42
Copy link
Owner

The solution on this issue is ugly, but really simple once you know how the models are historically loaded, and now loaded in Django 1.7

Deferring the loading of the Author models in zinnia.models by not importing it, let's Django start normally, but register the Entry and Category models.

Then when a components of Zinnia import the Author model, the Author model is registered and applied, like in the older versions of Django.

That's why each import of the Author model in Zinnia is done like that:

from zinnia.models.authors import Author

In this manner the Author model is only loaded when needed, not when the Zinnia's models are imported.

No more needs to build a profile models for author, the patch is just a removal of 2 lines.

Note the build is broken on Python 3, due to this issue https://code.djangoproject.com/ticket/23455 .

@Fantomas42
Copy link
Owner

Tests are now passing.

@gustavi
Copy link

gustavi commented Oct 19, 2014

I have an error when migrate :

django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'zinnia.Author'>]

Full log : http://paste.awesom.eu/hN4o

(I have edit my Author model with the "patch")

@Fantomas42
Copy link
Owner

What is the state of the database when you run the migrate command ?
What "patch" do you use ? Do you mean the feature/django1.7 branch ?

@gustavi
Copy link

gustavi commented Oct 19, 2014

The database is empty. Sorry I was using the dev branch and editing the Author model but using the feature/django1.7 is perfect !

@karolszk
Copy link

Hello All Zinnia Fans! :-)
I would like to know wwhat is the current status of this issue? Today I've installed zinnia 0.14.2 and django 1.7 and still I've got an exception:

from zinnia.models.author import Author

File "C:\Python27\lib\site-packages\zinnia\models\author.py", line 23, in
class Author(get_user_model(),
File "C:\Python27\lib\site-packages\django\contrib\auth__init__.py", line 136, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 199, in get_model
self.check_models_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
:(

Regards, K.

@bittner
Copy link
Contributor

bittner commented Oct 20, 2014

@karolszk There is a feature branch for Django 1.7.
I would assume you'd have to use Zinnia off this branch for Django 1.7 as long as this branch exists. Zinnia off the master branch works for Django versions below 1.7, I'd guess.

@karolszk
Copy link

@bittner thanks, but in branch django1.7 I don't see any changes in zinnia\models\author.py.
(still there is a call get_user_model() in definition of a class Author which is common mistake according to django officials doc:

"Another common culprit is django.contrib.auth.get_user_model(). Use the AUTH_USER_MODEL setting to reference the User model at import time."

(https://docs.djangoproject.com/en/1.7/ref/applications/)

But I'll try. :-)

Regards, K.

@raeuz
Copy link

raeuz commented Nov 3, 2014

Hi, i have clone Zinnia to my computer(git clone https://github.com/Fantomas42/django-blog-zinnia.git)
Anyone can tell me how to install the feature/django-1.7? Thanks.

@Fantomas42
Copy link
Owner

git checkout origin/feature/django-1.7

Did you even try searching for it ?

@raeuz
Copy link

raeuz commented Nov 3, 2014

@Fantomas42, Yet, i searched. i done the follows:

  1. git clone https://github.com/Fantomas42/django-blog-zinnia.git
  2. cd django-blog-zinnia
  3. git checkout -b django-1.7 remote/origin/feature/django-1.7
  4. python setup.py install

Above steps are OK?

Now, when i runserver, then open http://127.0.0.1:8000/zinniablog on browser, but i get these errors:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/zinniablog

Django Version: 1.7
Python Version: 3.4.1
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.sites',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_comments',
 'mptt',
 'tagging',
 'zinnia')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Template error:
In template F:\virtualenvs\django-blog-zinnia\lib\site-packages\django_blog_zinnia-0.14.2-py3.4.egg\zinnia\templates\zinnia\base.html, error at line 22
   request
   12 :     <link rel="author" type="text/plain" href="{% url 'zinnia:humans' %}" />


   13 :     <link rel="EditURI" type="application/rsd+xml" href="{% url 'zinnia:rsd' %}" />


   14 :     <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="{% url 'zinnia:wlwmanifest' %}" />


   15 :     <link rel="search" type="application/opensearchdescription+xml" title="Zinnia's Weblog" href="{% url 'zinnia:opensearch' %}" />


   16 :     <link rel="alternate" type="application/rss+xml" title="{% trans "RSS Feed of latest entries" %}" href="{% url 'zinnia:entry_latest_feed' %}" />


   17 :     <link rel="alternate" type="application/rss+xml" title="{% trans "RSS Feed of latest discussions" %}" href="{% url 'zinnia:discussion_latest_feed' %}" />


   18 :     {% get_archives_entries "zinnia/tags/entries_archives_link.html" %}


   19 : {% endblock link %}


   20 : 


   21 : {% block breadcrumbs %}


   22 :    {% zinnia_breadcrumbs %} 


   23 : {% endblock breadcrumbs %}


   24 : 


   25 : {% block sidebar %}


   26 : <div id="widget-welcome" class="widget">


   27 :   <h3>{% trans "Welcome!" %}</h3>


   28 :   <p>


   29 :     {% trans "This simple theme is the default appearance of Zinnia." %}


   30 :   </p>


   31 :   <p>


   32 :     {% trans "Don't hesitate to override the template <strong>zinnia/base.html</strong> to start <a href='http://docs.django-blog-zinnia.com/en/latest/how-to/customize_look_and_feel.html'>customizing your Weblog</a>." %}


Traceback:
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\core\handlers\base.py" in get_response
  137.                 response = response.render()
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\response.py" in render
  103.             self.content = self.rendered_content
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\response.py" in rendered_content
  80.         content = template.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in render
  148.             return self._render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in _render
  142.         return self.nodelist.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in render
  844.                 bit = self.render_node(node, context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\debug.py" in render_node
  80.             return node.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\loader_tags.py" in render
  126.         return compiled_parent._render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in _render
  142.         return self.nodelist.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in render
  844.                 bit = self.render_node(node, context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\debug.py" in render_node
  80.             return node.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\loader_tags.py" in render
  126.         return compiled_parent._render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in _render
  142.         return self.nodelist.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in render
  844.                 bit = self.render_node(node, context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\debug.py" in render_node
  80.             return node.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\loader_tags.py" in render
  126.         return compiled_parent._render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in _render
  142.         return self.nodelist.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in render
  844.                 bit = self.render_node(node, context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\debug.py" in render_node
  80.             return node.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in render
  844.                 bit = self.render_node(node, context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\debug.py" in render_node
  80.             return node.render(context)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\base.py" in render
  1207.                     _dict = func(*resolved_args, **resolved_kwargs)
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django_blog_zinnia-0.14.2-py3.4.egg\zinnia\templatetags\zinnia.py" in zinnia_breadcrumbs
  348.     path = context['request'].path
File "F:\virtualenvs\django-blog-zinnia\lib\site-packages\django-1.7-py3.4.egg\django\template\context.py" in __getitem__
  70.         raise KeyError(key)

Exception Type: KeyError at /zinniablog
Exception Value: 'request'

@Fantomas42
Copy link
Owner

@maniachhz I think it miss the 'django.core.context_processors.request' context processors.

Please follow carefully the install instruction.
Note this thread is not related to support, but for Django 1.7

@raeuz
Copy link

raeuz commented Nov 5, 2014

@Fantomas42 ,
It works now.
Thank you.

@itbabu
Copy link

itbabu commented Nov 6, 2014

Hi!
a little note for the documentation:

if you customize ZINNIA_ENTRY_CONTENT_TEMPLATES or ENTRY_CONTENT_TEMPLATES a new migration would be created inside the zinnia app directory.

A solution to avoid future conflicts is to create a custom zinnia migration module for zinnia

MIGRATION_MODULES = {

    'zinnia': 'my_utils.migrations_zinnia'
}

and then run a

python manage.py makemigrations zinnia

@mrhwick
Copy link

mrhwick commented Nov 17, 2014

@Fantomas42, are you planning to include this feature branch in the next release of zinnia?

If there are issues blocking you from merging this feature branch into master, what needs to be done in order to resolve them?

@Fantomas42
Copy link
Owner

Yes the branch is planned to be merged and to be in the next release of Zinnia.
I just need to time, few hours to be in the good spirit and make the things in the right way.

Be patient.

@coldmind
Copy link

What need to be done in django1.7 feature branch?
Maybe I or someone else will finish this work.

@Fantomas42
Copy link
Owner

I have a list of things to be done, with 3-4 remaining points, which I can't delegate, mainly documentation and testing new features introduced in Django 1.7,

@coldmind
Copy link

coldmind commented Dec 5, 2014

Found workaround of issue with get_user_model in ticket https://code.djangoproject.com/ticket/22872:

===================================================================
--- zinnia/models/__init__.py   (revision a85e910b57a920ae10e5d30be4d32614c8e87268)
+++ zinnia/models/__init__.py   (revision )
@@ -1,6 +1,7 @@
 """Models for Zinnia"""
 from django_comments.moderation import moderator

+from zinnia.models.author import Author
 from zinnia.models.entry import Entry
 from zinnia.models.category import Category

@@ -14,6 +15,7 @@
 # when the Zinnia's URLs are parsed. Issue #161.
 # Issue #161, seems not valid since Django 1.7.
 __all__ = [Entry.__name__,
+           Author.__name__,
            Category.__name__]

===================================================================
--- zinnia/models/author.py (revision a85e910b57a920ae10e5d30be4d32614c8e87268)
+++ zinnia/models/author.py (revision )
@@ -1,12 +1,16 @@
 """Author model for Zinnia"""
+from django.apps import apps
 from django.db import models
-from django.contrib.auth import get_user_model
+from django.conf import settings
 from django.utils.encoding import python_2_unicode_compatible

 from zinnia.managers import entries_published
 from zinnia.managers import EntryRelatedPublishedManager


+user_app, user_model = settings.AUTH_USER_MODEL.split('.')
+
+
 class AuthorPublishedManager(models.Model):
     """
     Proxy model manager to avoid overriding of
@@ -19,7 +23,7 @@


 @python_2_unicode_compatible
-class Author(get_user_model(),
+class Author(apps.get_app_config(user_app).get_model(user_model),
              AuthorPublishedManager):
     """
     Proxy model around :class:`django.contrib.auth.models.get_user_model`.

@Fantomas42
Copy link
Owner

Interesting, tests needed.

@faraggi
Copy link

faraggi commented Mar 1, 2015

I am getting the same or similar error on python 3.4.0 django 1.7.5.
I have tried with the django1.7 branch, develop branch and with the master branch.
This is the output of migrate:

(project)username@computername:~/project/application$ python manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: bootstrap3
  Apply all migrations: project, activity, zinnia, sessions, auth, badge, admin, coupon, contenttypes, sites
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations: Applying zinnia.0001_initial...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/db/migrations/executor.py", line 96, in apply_migration
    if self.detect_soft_applied(migration):
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/db/migrations/executor.py", line 140, in detect_soft_applied
    apps = project_state.render()
  File "/home/username/.virtualenvs/project/local/lib/python3.4/site-packages/django/db/migrations/state.py", line 75, in render
    "for more" % new_unrendered_models
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'zinnia.Author'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
 in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more

@argaen
Copy link

argaen commented Mar 9, 2015

Samer error here with django==1.7.5 and django-blog-zinnia==0.15.1

@Fantomas42
Copy link
Owner

@argaen do you have customized the User model ?

@aniav
Copy link

aniav commented Mar 9, 2015

I have the same error with a customized User model on django==1.7.4 and django.blog.zinnia==0.15.1.

@faraggi
Copy link

faraggi commented Mar 9, 2015

Oh good, I thought I was the only one there for a moment.

@argaen, @aniav What are your user model customizations? (if any)
I've created a subclass of AbstractBaseUser in which I change some basic attributs like first_name and date_joined etc....
I also have a property decorator on the username function.

I can't seem to discover what is bugging the migration.

@aniav
Copy link

aniav commented Mar 9, 2015

My user model has no username, only email as a username field. In my case the migration should have been faked as it turned out, because all the tables already existed - but I should now create a separate migration on my side that would change the foreign key constraint for zinnia blog author and set it on the new user model. My application was upgraded from Django 1.4 to 1.7 recently, that's why I had tables created earlier and had to fake migrations.

@argaen
Copy link

argaen commented Mar 10, 2015

@Fantomas42 @faraggi Yeah, I have custom User model. It inherits from AbstracUser to add a couple of fields.

@RossLYoung
Copy link

Me too. From #400 , I added to the zinnia initial migration......

from django.conf import settings
class Migration(migrations.Migration):

    dependencies = [
        ('auth', '0001_initial'),
        ('sites', '0001_initial'),
        (migrations.swappable_dependency(settings.AUTH_USER_MODEL)),
    ]

The initial migration now works.

@pgcd
Copy link

pgcd commented Mar 24, 2015

Having the same problem (with custom user model), and @RossLYoung solution works for me.

@faraggi
Copy link

faraggi commented Mar 26, 2015

@RossLYoung @argaen @aniav Thanks RossLYoung, your solution also worked for me.

@argaen
Copy link

argaen commented Mar 27, 2015

+1 here. @RossLYoung solution works.

@kcolton
Copy link

kcolton commented Apr 1, 2015

+1 - @RossLYoung solution worked for me. My workaround: created a copy of the migration, made @RossLYoung change and an entry in MIGRATION_MODULES like 'zinnia': 'ext.zinnia_migrations'

@harshaddevale-tudip
Copy link

harshaddevale-tudip commented Feb 6, 2017

Hi,
I am getting error for django-1.7.1, django-blog-zinnia==0.14.2 and python 2.7

This is the output i get when trying to migrate:
Traceback (most recent call last):
File "manage.py", line 14, in
execute_from_command_line(sys.argv)
File "/home/venv/local/lib/python2.7/site-packages/django/core/management/init.py", line 385, in execute_from_command_line
utility.execute()
File "/home/venv/local/lib/python2.7/site-packages/django/core/management/init.py", line 354, in execute
django.setup()
File "/home/venv/local/lib/python2.7/site-packages/django/init.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/venv/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/venv/local/lib/python2.7/site-packages/zinnia/models/init.py", line 5, in
from zinnia.models.author import Author
File "/home/venv/local/lib/python2.7/site-packages/zinnia/models/author.py", line 22, in
class Author(get_user_model(),
File "/home/venv/local/lib/python2.7/site-packages/django/contrib/auth/init.py", line 136, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL)
File "/home/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 199, in get_model
self.check_models_ready()
File "/home/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

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

No branches or pull requests