Repository: fedora-infra/bodhi

Issue:
RSS: ValueError: Required fields not set
We see periodic HTTP 500's in the logs from users requesting RSS URLs like this:

https://bodhi.fedoraproject.org/rss/comments/?updates=FEDORA-2017-12e76e8364

```
2018-04-24 14:34:22,567 ERROR [bodhi.server][MainThread] Error caught.  Handling HTML response.
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pyramid/tweens.py", line 39, in excview_tween
    response = handler(request)
  File "/usr/lib/python2.7/site-packages/pyramid/router.py", line 156, in handle_request
    view_name
  File "/usr/lib/python2.7/site-packages/pyramid/view.py", line 617, in _call_view
    response = view_callable(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/config/views.py", line 181, in __call__
    return view(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/viewderivers.py", line 389, in attr_view
    return view(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/viewderivers.py", line 367, in predicate_wrapper
    return view(context, request)
  File "/usr/lib/python2.7/site-packages/pyramid/viewderivers.py", line 461, in rendered_view
    request, result, view_inst, context)
  File "/usr/lib/python2.7/site-packages/pyramid/renderers.py", line 435, in render_view
    return self.render_to_response(response, system, request=request)
  File "/usr/lib/python2.7/site-packages/pyramid/renderers.py", line 458, in render_to_response
    result = self.render(value, system_values, request=request)
  File "/usr/lib/python2.7/site-packages/pyramid/renderers.py", line 454, in render
    result = renderer(value, system_values)
  File "/usr/lib/python2.7/site-packages/bodhi/server/renderers.py", line 111, in render
    return feed.rss_str()
  File "/usr/lib/python2.7/site-packages/feedgen/feed.py", line 398, in rss_str
    feed, doc = self._create_rss(extensions=extensions)
  File "/usr/lib/python2.7/site-packages/feedgen/feed.py", line 374, in _create_rss
    item = entry.rss_entry()
  File "/usr/lib/python2.7/site-packages/feedgen/entry.py", line 186, in rss_entry
    raise ValueError('Required fields not set')
ValueError: Required fields not set
2018-04-24 14:34:22,677 ERROR [bodhi.server][MainThread] Unhandled exception raised:  <html_handler at 0x7f7d360a5280 500 Internal Server Error>
```


Discussion:

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -3946,6 +3946,16 @@ def unique_testcase_feedback(self):
 
         return filtered_feedbacks
 
+    @property
+    def rss_title(self):
+        """
+        Return a formatted title for the comment using update alias and comment id.
+
+        Returns:
+            basestring: A string represenatation of the comment for RSS feed.
+        """
+        return "{} comment #{}".format(self.update.alias, self.id)
+
     def __json__(self, *args, **kwargs):
         """
         Return a JSON string representation of this comment.
diff --git a/bodhi/server/renderers.py b/bodhi/server/renderers.py
--- a/bodhi/server/renderers.py
+++ b/bodhi/server/renderers.py
@@ -87,7 +87,7 @@ def link_dict(obj):
                 'description': operator.itemgetter('name'),
             },
             'comments': {
-                'title': operator.itemgetter('text'),
+                'title': operator.itemgetter('rss_title'),
                 'link': linker('comment', 'id', 'id'),
                 'description': operator.itemgetter('text'),
                 'pubdate': lambda obj: utc.localize(obj['timestamp']),
@@ -105,7 +105,7 @@ def link_dict(obj):
             for name, getter in getters[key].items():
                 # Because we have to use methods to fill feed entry attributes,
                 # it's done by getting methods by name and calling them
-                # on the same line
+                # on the same line.
                 getattr(feed_item, name)(getter(value))
 
         return feed.rss_str()


Test patch:
diff --git a/bodhi/tests/server/services/test_comments.py b/bodhi/tests/server/services/test_comments.py
--- a/bodhi/tests/server/services/test_comments.py
+++ b/bodhi/tests/server/services/test_comments.py
@@ -314,6 +314,16 @@ def test_list_comments_rss(self):
         self.assertIn('application/rss+xml', res.headers['Content-Type'])
         self.assertIn('srsly.  pretty good', res)
 
+    def test_list_comments_rss_failing_condition(self):
+        comment = self.db.query(Comment).first()
+        comment.text = u''
+        self.db.flush()
+
+        res = self.app.get('/rss/comments/',
+                           headers=dict(accept='application/atom+xml'))
+        self.assertIn('application/rss+xml', res.headers['Content-Type'])
+        self.assertIn("{} comment #{}".format(comment.update.alias, comment.id), res)
+
     def test_list_comments_page(self):
         res = self.app.get('/comments/', headers=dict(accept='text/html'))
         self.assertIn('text/html', res.headers['Content-Type'])