Model validation issue with FeinCMSTools

22 views
Skip to first unread message

Julien Phalip

unread,
Mar 11, 2013, 9:24:34 PM3/11/13
to glamki...@googlegroups.com
Hi,

I'm starting a fresh new project with FeinCMS 1.7.1 and the latest commit of FeinCMSTools [1]. I've followed the README instructions with something quite simple:

models.py
=========

    from django.db import models
    from pages.content_types import Text

    class Page(FeinCMSDocument):
        title = models.CharField(max_length=255)

        feincms_regions = (
                ('body', 'Body'),
            )

        @classmethod
        def content_types_by_region(cls, region):
            return [
                (None, (Text,))
            ]

content_types.py
==============

    from django.db import models
    from feincmstools.base import Content

    class Text(Content):
        text = models.TextField()

        class Meta:
            abstract=True

And I'm getting the following error when I try to run 'migrate' or 'syncdb':

    CommandError: One or more models did not validate:
    pages.text: 'parent' has a relation with model <class 'pages.models.Page'>, which has either not been installed or is abstract.

I wonder if this could be related to the issue discussed in [2].

Am I missing something? Perhaps the documentation needs to be revised?

Thanks!

Julien

Greg Turner

unread,
Mar 12, 2013, 12:19:16 AM3/12/13
to glamki...@googlegroups.com
Hi Julien,

I couldn't reproduce this with Django 1.4.1, but did see the same results as you have with Django 1.5. I'm looking into it some more. Meanwhile, can you try an install of Django 1.4.1 and see if the error goes away?

Greg.

--
You received this message because you are subscribed to the Google Groups "glamkit-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glamkit-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Julien Phalip

unread,
Mar 12, 2013, 12:40:50 AM3/12/13
to glamki...@googlegroups.com
Hey Greg,

Thanks for the quick reply!

I confirm that things work fine for me with 1.4.3. I only get the error with Django 1.5. Strange that...

Julien

Greg Turner

unread,
Mar 12, 2013, 8:21:40 PM3/12/13
to glamki...@googlegroups.com
I've submitted a patch in https://github.com/feincms/feincms/issues/323. Give it a try and let me know if it works for you.

ensure_completely_loaded's call to get_models was resulting in bad values in the get_models() cache in Django 1.5. Clearing the cache fixes the problem.

Funnily enough, we don't experience this problem in a larger project, possibly because the greater number of models to register means that there are a few more models to be registered after ensure_completely_loaded's work is done.

It may be that calling ensure_completely_loaded with force=False is sufficient for Django 1.5, since its approach to model registration appears to be different, due to swappable models. But that requires Django knowledge beyond my ken.

Greg.

Aram Dulyan

unread,
Mar 12, 2013, 8:40:25 PM3/12/13
to glamki...@googlegroups.com
The core of the problem, as I see it, actually lies with Django, and the fact that it doesn't invalidate the models cache after loading a new app. So when we first call get_models in feincms, we're still in the middle of a load_app call, and we prematurely populate the cache, which never gets cleared, so the models from our new app are never returned on subsequent get_models calls, unless it's called with a different argument signature.

The ideal solution to this problem is to stick in a self._get_models_cache.clear() call at the end of django.db.models.loading.AppCache.load_app(), right before it returns. I'll create a Django ticket at some point.

For now, Greg's patch is a perfectly acceptable solution to the problem, in that it counters the side effect of prematurely populating the models cache by clearing it when it's done.

Julien Phalip

unread,
Mar 13, 2013, 8:11:25 PM3/13/13
to glamki...@googlegroups.com
Thanks a lot Greg and Aram. I confirm that this fix appears to solve my issue.

Like you suggest it might make sense to eventually fix that in Django itself. I'm going to PyCon this weekend and will talk about this with Jannis Leidel and  Preston Holmes, two Django committers who've done a lot of work in the app-refactor branch (which will hopefully land in 1.6).

Cheers!

Julien

Julien Phalip

unread,
Mar 14, 2013, 1:33:42 PM3/14/13
to glamki...@googlegroups.com
Hey,

I just wanted to note that FeinCMS 1.7.2 just got released, including the fix you've submitted.

Thanks guys!

Julien
Reply all
Reply to author
Forward
0 new messages