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

Enabling "related pages" causes server error 500 #586

Open
sebastian-muthwill opened this issue Jul 11, 2023 · 5 comments
Open

Enabling "related pages" causes server error 500 #586

sebastian-muthwill opened this issue Jul 11, 2023 · 5 comments
Labels
Type: Bug Something isn't working

Comments

@sebastian-muthwill
Copy link

sebastian-muthwill commented Jul 11, 2023

Describe the bug

I updated from version 1.0* to 2.1.2 and everything went fine except the new related pages feature is not working. It causes a server error 500.

Steps to reproduce

Steps to reproduce the behavior:

  1. Created some article pages and added classifiers (have already existed before update)
  2. switch on related pages on one article and select one classifier
  3. publish page
  4. open page results in server error 500

Error: AttributeError: WhereNode' object has no attribute 'select_format'

Template error:
In template /Users/sebastian/Documents/development/python/easy-ticket/easy-tickets/venv/lib/python3.9/site-packages/coderedcms/templates/coderedcms/pages/base.html, error at line 156
   'WhereNode' object has no attribute 'select_format'
   146 :     </div>
   147 :     {% include "coderedcms/includes/pagination.html" with items=index_paginated %}
   148 :     {% endif %}
   149 :     {% endblock %}
   150 : 
   151 :     {% block related_content %}
   152 :     {% if page.related_show %}
   153 :     <div class="container">
   154 :       <h2 class="text-center my-5">{% trans "Related" %}</h2>
   155 :       <div class="row">
   156 :          {% for rp in related_pages %} 
   157 :         <div class="col-sm-6 col-lg-4">
   158 :           {% include rp.miniview_template with page=rp %}
   159 :         </div>
   160 :         {% endfor %}
   161 :       </div>
   162 :     </div>
   163 :     {% endif %}
   164 :     {% endblock %}
   165 : 
   166 :     {% endblock %}

Expected behavior

Page can be viewed and related pages are showing up

Additional context

I went thru the documentation and saw the "upgrade considerations" part here: https://docs.coderedcorp.com/wagtail-crx/releases/v2.1.0.html
I was not sure if this is necessary or if it will only turn on the related pages on all existing pages (what it seems to be most likely)

And yes, I did apply all migrations after upgrading to the new versions and ran both makemigrations as well as migrate.

My installation is within a "webpages" app in django and I created an own ArticlePage subclassing CoderedArticlePage. Not sure if this could causing the issue.

@sebastian-muthwill sebastian-muthwill added the Type: Bug Something isn't working label Jul 11, 2023
@vsalvino
Copy link
Contributor

This is an unexpected error.. I'm not familiar with any objects or methods named WhereNode or select_format.

On your custom ArticlePage, are you by chance overriding the get_context() method? If so, be sure to override it as so:

def get_context(self, request):
    context = super().get_context(request)
    # custom code here, add to context
    ...
    return context

@cjkpl
Copy link
Contributor

cjkpl commented Aug 10, 2023

This may be related to the following:

The new functionality - "get_related_pages" in page_models assumes that the parent page derives from any CMS pages - but if the parent page is a regular wagtail page, the following line will causes an exception, not finding the expected method get_index_children().

r_qs = self.get_parent().specific.get_index_children()

@vsalvino Please advise if this is expected behaviour / do you assume that non-cms pages are not allowed in the page tree?

@vsalvino
Copy link
Contributor

Yes - we make the assumption that all pages which are parents or children of any page derived from CoderedPage are also derived from CoderedPage. So yes that is expected behavior. Nearly all features of CRX depend on CoderedPage.

I would recommend simply changing any of your models which inherit from Page to inherit from CoderedPage instead. Then run makemigrations.

Otherwise, you may have to shim your page model quite a bit, for example adding get_index_children, etc. That is a slippery slope which is probably not worth the trouble.

@cjkpl
Copy link
Contributor

cjkpl commented Aug 18, 2023

Hi,
Thanks for your detailed reply.

Considering that you actually do not forbid users to use plain Page models, would it be helpful to have a try/catch around the problematic line, not to leave the users in the dark with a potential E500?

@vsalvino
Copy link
Contributor

There are 100s of different things that would have to be try/catch, it would probably double the size of the codebase. So that is not something we are interested in.

You can still use normal wagtail Page models - but they cannot be parents or children of CoderedPage-derived models.

Similarly, wagtail requires all models to inherit from Page. What you are asking would be equivalent of having a wagtail page that does not inherit from Page. So it is really not possible or at least not worth the trouble.

Sorry I can't be more helpful on this... but the recommended fix would be to change your models from inheriting Page to CoderedPage, then run makemigrations.


I'm not sure if this inheritance structure described by @cjkpl is related to the original comment. @sebastian-muthwill do you think this could be part of your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants