Opened 9 years ago

Closed 9 years ago

#5415 closed defect (fixed)

Server error when trying to access media with graveyards comments

Reported by: ayleph Owned by:
Priority: blocker Milestone: 0.9.0
Component: programming Keywords: graveyard, comments
Cc: tsyesika Parent Tickets:

Description

As a logged in user, if I try to access a media page with a graveyard comment, I get a server error with the text below in my log. If I'm not logged in, then the comments aren't displayed, so the error doesn't occur.

Error - <class 'jinja2.exceptions.UndefinedError'>: 'mediagoblin.db.models.Graveyard object' has no attribute 'get_actor'
URL: https://goblinrefuge.com/mediagoblin/u/sushibsd/m/dank-wats/
File '/path/to/mediagoblin/lib/python2.7/site-packages/Paste-1.7.5.1-py2.7.egg/paste/exceptions/errormiddleware.py', line 144 in __call__
  app_iter = self.application(environ, sr_checker)
File '/path/to/mediagoblin/mediagoblin/app.py', line 342 in __call__
  return self.call_backend(environ, start_response)
File '/path/to/mediagoblin/lib/python2.7/site-packages/Werkzeug-0.10.1-py2.7.egg/werkzeug/wsgi.py', line 591 in __call__
  return self.app(environ, start_response)
File '/path/to/mediagoblin/mediagoblin/app.py', line 276 in call_backend
  return self._finish_call_backend(request, environ, start_response)
File '/path/to/mediagoblin/mediagoblin/app.py', line 318 in _finish_call_backend
  response = controller(request)
File '/path/to/mediagoblin/mediagoblin/decorators.py', line 47 in wrapper
  return controller(request, *args, **kwargs)
File '/path/to/mediagoblin/mediagoblin/decorators.py', line 210 in wrapper
  return controller(request, media=media, *args, **kwargs)
File '/path/to/mediagoblin/mediagoblin/decorators.py', line 170 in wrapper
  return controller(request, page=page, *args, **kwargs)
File '/path/to/mediagoblin/mediagoblin/user_pages/views.py', line 170 in media_home
  context)
File '/path/to/mediagoblin/mediagoblin/tools/response.py', line 36 in render_to_response
  render_template(request, template, context),
File '/path/to/mediagoblin/mediagoblin/tools/template.py', line 144 in render_template
  rendered = template.render(context)
File '/path/to/mediagoblin/lib/python2.7/site-packages/Jinja2-2.7.3-py2.7.egg/jinja2/environment.py', line 969 in render
  return self.environment.handle_exception(exc_info, True)
File '/path/to/mediagoblin/lib/python2.7/site-packages/Jinja2-2.7.3-py2.7.egg/jinja2/environment.py', line 742 in handle_exception
  reraise(exc_type, exc_value, tb)
File '/path/to/mediagoblin/mediagoblin/templates/mediagoblin/media_displays/video.html', line 19 in top-level template code 
  {% extends 'mediagoblin/user_pages/media.html' %}
File '/path/to/mediagoblin/mediagoblin/templates/mediagoblin/user_pages/media.html', line 21 in top-level template code 
  {% from "mediagoblin/utils/pagination.html" import render_pagination %}
File '/var/lib/mediagoblin/templates/mediagoblin/base.html', line 64 in top-level template code 
  {% block mediagoblin_body %}
File '/var/lib/mediagoblin/templates/mediagoblin/base.html', line 203 in block "mediagoblin_body"
  {% block mediagoblin_content %}
File '/path/to/mediagoblin/mediagoblin/templates/mediagoblin/user_pages/media.html', line 136 in block "mediagoblin_content"
  <a href="{{ request.urlgen('mediagoblin.user_pages.user_home',
File '/path/to/mediagoblin/lib/python2.7/site-packages/Jinja2-2.7.3-py2.7.egg/jinja2/environment.py', line 397 in getattr
  return getattr(obj, attribute)
UndefinedError: 'mediagoblin.db.models.Graveyard object' has no attribute 'get_actor'

The problematic code is in mediagoblin/templates/mediagoblin/user_pages/media.html.

      {% for comment in comments %}
        {% set comment_author = comment.get_actor %}
        <li id="comment-{{ comment.id }}"
          {%- if pagination.active_id == comment.id %}
            class="comment_wrapper comment_active">
            <a name="comment" id="comment"></a>
          {%- else %}
            class="comment_wrapper">
          {%- endif %}
          <div class="comment_author">
            <img src="{{ request.staticdirect('/images/icon_comment.png') }}" />
            <a href="{{ request.urlgen('mediagoblin.user_pages.user_home',
                            user=comment_author.username) }}"
               class="comment_authorlink">
              {{- comment_author.username -}}
            </a>
            <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
                            comment=comment.id,
                            user=media.get_actor.username,
                            media=media.slug_or_id) }}#comment"
               class="comment_whenlink">
              <span title='{{- comment.created.strftime("%I:%M%p %Y-%m-%d") -}}'>
                {%- trans formatted_time=timesince(comment.created) -%}
                  {{ formatted_time }} ago
                {%- endtrans -%}
              </span></a>:
          </div>

comment in comments appears to return graveyard comments as well, and these comments don't have a get_actor attribute.

Change History (2)

comment:1 by ayleph, 9 years ago

Digging deeper, comments comes from mediagoblin/user_pages/views.py.

def media_home(request, media, page, **kwargs):
    """ 
    'Homepage' of a MediaEntry()
    """
    comment_id = request.matchdict.get('comment', None)
    if comment_id:
        if request.user:
            mark_comment_notification_seen(comment_id, request.user)

        pagination = Pagination(
            page, media.get_comments(
                mg_globals.app_config['comments_ascending']),
            MEDIA_COMMENTS_PER_PAGE,
            comment_id)
    else:
        pagination = Pagination(
            page, media.get_comments(
                mg_globals.app_config['comments_ascending']),
            MEDIA_COMMENTS_PER_PAGE)

    comments = pagination()

    comment_form = user_forms.MediaCommentForm(request.form)

    media_template_name = media.media_manager.display_template

    context = { 
        'media': media,
        'comments': comments,
        'pagination': pagination,
        'comment_form': comment_form,
        'app_config': mg_globals.app_config}

    # Since the media template name gets swapped out for each media
    # type, normal context hooks don't work if you want to affect all
    # media displays.  This gives a general purpose hook.
    context = hook_transform(
        "media_home_context", context)

    return render_to_response(
        request,
        media_template_name,
        context)

The group of comments is created by get_comments which is in mediagoblin/db/models.py.

    def get_comments(self, ascending=False):
        query = Comment.query.join(Comment.target_helper).filter(and_(
            GenericModelReference.obj_pk == self.id,
            GenericModelReference.model_type == self.__tablename__
        ))

        if ascending:
            query = query.order_by(Comment.added.asc())
        else:
            qury = query.order_by(Comment.added.desc())

        return FakeCursor(query, lambda c:c.comment())

comment:2 by Jessica Tallon, 9 years ago

Resolution: fixed
Status: newclosed

This has been fixed as of 2104c3e. Please test and re-open if you don't think it's fixed.

NB: there is a migration also so ensure you run those.

Note: See TracTickets for help on using tickets.