Fixed a UnicodeError in the sql.models.MediaEntry
authorJoar Wandborg <git@wandborg.com>
Fri, 3 Aug 2012 14:02:18 +0000 (16:02 +0200)
committerJoar Wandborg <git@wandborg.com>
Fri, 3 Aug 2012 14:02:18 +0000 (16:02 +0200)
The __repr__() call would crash the process when it tried to convert an
unicode title to ASCII for terminal/logfile output.

mediagoblin/db/sql/models.py

index 6ce4e06fafdf93296552f68c10f6dab8afd17619..7c8c0f99be05469eea3a507964014f16e5194aa4 100644 (file)
@@ -212,10 +212,12 @@ class MediaEntry(Base, MediaEntryMixin):
         return sys.modules[models_module].DATA_MODEL
 
     def __repr__(self):
+        safe_title = self.title.encode('ascii', 'replace')
+
         return '<{classname} {id}: {title}>'.format(
                 classname=self.__class__.__name__,
                 id=self.id,
-                title=self.title)
+                title=safe_title)
 
 
 class FileKeynames(Base):