Modify

Opened 8 years ago

Closed 7 years ago

#13196 closed defect (fixed)

Decode bytestrings to Unicode before storing them in the DB

Reported by: Peter Suter Owned by: Peter Suter
Priority: normal Component: OnSiteNotificationsPlugin
Severity: normal Keywords:
Cc: Trac Release:

Description

From the mailing list:

I now see the following in my browser and Trac log file:

"Warning: The change has been saved, but an error occurred while sending notifications: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings. "

That message is raised from SQLite bindings.

I guess this plugin uses utf-8 bytestring to create record when sending notification.

diff --git a/onsitenotificationsplugin/trunk/onsitenotifications/web_ui.py
b/onsitenotificationsplugin/trunk/onsitenotifications/web
index 3499c4dd8..59fdb3432 100644
--- a/onsitenotificationsplugin/trunk/onsitenotifications/web_ui.py
+++ b/onsitenotificationsplugin/trunk/onsitenotifications/web_ui.py
@@ -12,6 +12,7 @@ from trac.resource import Resource,
get_resource_description, get_resource_url
 from trac.web.api import IRequestHandler
 from trac.web.chrome import add_ctxtnav, INavigationContributor
 from trac.util.compat import set
+from trac.util.text import to_unicode

 from onsitenotifications.model import OnSiteMessage

@@ -72,6 +73,7 @@ class OnSiteNotificationsDistributor(Component):

         for fmt, sids in msgdict.iteritems():
             message = formats[fmt].format(transport, fmt, event)
+            message = to_unicode(message)
             for sid, authenticated in sids:
                 OnSiteMessage.add(self.env, sid, authenticated, message,
                                   event.realm, get_target_id(event.target))

Attachments (0)

Change History (2)

comment:1 Changed 7 years ago by Peter Suter

In 16948:

OnSiteNotificationsPlugin: Decode bytestrings to Unicode before storing them in the DB.
(see #13196)

comment:2 Changed 7 years ago by Peter Suter

Resolution: fixed
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Peter Suter.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.