Opened 8 years ago

Closed 8 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:


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'
File '/path/to/mediagoblin/lib/python2.7/site-packages/Paste-', line 144 in __call__
  app_iter = self.application(environ, sr_checker)
File '/path/to/mediagoblin/mediagoblin/', 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/', line 591 in __call__
  return, start_response)
File '/path/to/mediagoblin/mediagoblin/', line 276 in call_backend
  return self._finish_call_backend(request, environ, start_response)
File '/path/to/mediagoblin/mediagoblin/', line 318 in _finish_call_backend
  response = controller(request)
File '/path/to/mediagoblin/mediagoblin/', line 47 in wrapper
  return controller(request, *args, **kwargs)
File '/path/to/mediagoblin/mediagoblin/', line 210 in wrapper
  return controller(request, media=media, *args, **kwargs)
File '/path/to/mediagoblin/mediagoblin/', line 170 in wrapper
  return controller(request, page=page, *args, **kwargs)
File '/path/to/mediagoblin/mediagoblin/user_pages/', line 170 in media_home
File '/path/to/mediagoblin/mediagoblin/tools/', line 36 in render_to_response
  render_template(request, template, context),
File '/path/to/mediagoblin/mediagoblin/tools/', 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/', 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/', 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/', 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-{{ }}"
          {%- if pagination.active_id == %}
            class="comment_wrapper comment_active">
            <a name="comment" id="comment"></a>
          {%- else %}
          {%- 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) }}"
              {{- comment_author.username -}}
            <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
                            media=media.slug_or_id) }}#comment"
              <span title='{{- comment.created.strftime("%I:%M%p %Y-%m-%d") -}}'>
                {%- trans formatted_time=timesince(comment.created) -%}
                  {{ formatted_time }} ago
                {%- endtrans -%}

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, 8 years ago

Digging deeper, comments comes from mediagoblin/user_pages/

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(
        pagination = Pagination(
            page, media.get_comments(

    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(

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

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

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

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

comment:2 by Jessica Tallon, 8 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.