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

Getting "Entry object has no attribute get_ancestors" if Entry is empty #59

Open
paramono opened this issue Nov 28, 2016 · 4 comments
Open

Comments

@paramono
Copy link
Contributor

I found quite a silly bug related to interopability of feincms and elephantblog.

If you create an empty elephantblog entry (by "empty" I mean with no content types added to it), then the following error will appear:

'Entry' object has no attribute 'get_ancestors'
(Line in question)

Although it's not something critical, since website administrators are unlikely to create a post with no content blocks, still, if somebody does that by accident, it's a little annoying.

I wonder how to fix this issue? Wrap get_ancestors in try/except, and catch the potential error? Or do something on elephant_blog side?

@matthiask
Copy link
Member

Oh yes, that's very annoying.

The right thing to do would be add a subclass of ContentProxy with a custom _inherit_from() method that does nothing to elephantblog, and set content_proxy_class on the Entry model (https://github.com/feincms/feincms/blob/8e30d925b369df169cd44ee8d030647e0c1dd0a3/feincms/models.py#L438)

If it weren't for backwards compatibility that should be the default though, and the get_ancestors() handling should be limited to the FeinCMS page model.

@paramono
Copy link
Contributor Author

I also managed to pinpoint what exactly causes the problem.

I realized that I get the error only if any of the Entry regions has inherited string defined in register_regions. Here's an example of an erroneous setup:

Entry.register_regions(
    ('main', 'Main', 'inherited'),
    ('preview', 'Preview'),
)

In that case, either of the regions will raise an error as soon as you try to render it. Of course, you can create 'template guards' like this:

{% if entry.content.preview %}
    {% feincms_render_region entry 'preview' request %}
{% endif %}

But there's not much point in that, you can simply omit 'inherited' from register_regions method, and the problem will disappear.

By the way, what is the supposed behavior for Entries with inherited regions? Should they inherit regions from the Page that hosts them? And does this information affect "the right way" to fix it?

@matthiask
Copy link
Member

I never thought about entries inheriting content from pages or anything similar – we only ever used inheriting regions with page trees. It never occurred to me that inheritance might also be used in the context of blog entries, but why not?

@barseghyanartur
Copy link

For me the solution was quite simple (for custom Entry models - extensions to the ElephantBlog models):

from feincms.models import Base
from feincms.module.mixins import ContentModelMixin
from feincms.module.page.models import Page

class EventEntry(Base, ContentModelMixin):
   
    # ... other things

    def get_ancestors(self, *args, **kwargs):
        return Page.objects.none()

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