Commits

Mike Bayer committed 922a7be

- Fixed bug where a NULL stored as the
author of a ticket comment would
cause a variety of NoneType errors.

Comments (0)

Files changed (3)

+1.6
+---
+- Fixed bug where a NULL stored as the
+  author of a ticket comment would
+  cause a variety of NoneType errors.
+
 1.5
 ---
 
-- Detect if https:// is in use, generate 
+- Detect if https:// is in use, generate
   https:// Gravatars in this case.
 
 - Fixed bug whereby ui would crash on

tracvatar/__init__.py

-__version__ = '1.5'
+__version__ = '1.6'

tracvatar/web_ui.py

             filter_.append(self._prefs_filter(context))
 
         filter_.append(self._footer())
+
         self._lookup_email(author_data)
         for f in filter_:
             if f is not None:
     def _footer(self):
         return Transformer('//div[@id="footer"]/p[@class="left"]').append(tag.p(
             "Gravatar support by ",
-            tag.a("Tracvatar %s" % tracvatar.__version__, 
+            tag.a("Tracvatar %s" % tracvatar.__version__,
                     href="https://bitbucket.org/zzzeek/tracvatar"),
             class_="left",
         ))
         return lambda stream: Transformer('//table[@id="info"]//th').prepend(
             self._generate_avatar(
                     context,
-                    author, 
-                    "browser-changeset", 
+                    author,
+                    "browser-changeset",
                     self.browser_changeset_size)
         )(stream)
 
                     prepend(
                         self._generate_avatar(
                             context,
-                            author, 
-                            'ticket-reporter', 
+                            author,
+                            'ticket-reporter',
                             self.ticket_reporter_size)
                         )(stream)
 
             author = apply_authors.pop()
             tag = self._generate_avatar(
                         context,
-                        author, 
-                        'ticket-comment', 
+                        author,
+                        'ticket-comment',
                         self.ticket_comment_size)
             return itertools.chain([next(stream)], tag, stream)
 
             author = apply_authors.pop()
             tag = self._generate_avatar(
                         context,
-                        author, 
-                        'timeline', 
+                        author,
+                        'timeline',
                         self.timeline_size)
             return itertools.chain(tag, stream)
 
     _long_author_re = re.compile(r'.*<([^@]+)@([^@]+)>\s*|([^@]+)@([^@]+)')
 
     def _gravatar(self, email):
+        if email is None:
+            email = ''
         return hashlib.md5(email.lower()).hexdigest()
 
     def _lookup_email(self, author_data):
-        lookup_authors = sorted([a for a in author_data if '@' not in a])
+        author_names = [a for a in author_data if a]
+        lookup_authors = sorted([a for a in author_names
+                                if '@' not in a])
+        email_authors = set(author_names).difference(lookup_authors)
+
         if lookup_authors:
             db = self.env.get_db_cnx()
             cursor = db.cursor()
             cursor.execute(
-                "select sid, value from session_attribute where name=%%s and sid in (%s)" % (
+                "select sid, value from session_attribute "
+                "where name=%%s and sid in (%s)" % (
                     ",".join(["%s" for author in lookup_authors])
                 ), ("email",) + tuple(lookup_authors)
             )
             for sid, email in cursor.fetchall():
                 author_data[sid] = self._gravatar(email)
 
-        for author in set(author_data).difference(lookup_authors):
+        for author in email_authors:
             author_info = self._long_author_re.match(author)
             if author_info:
                 if author_info.group(1):