Edgewall Software
Modify

Opened 15 years ago

Last modified 11 years ago

#580 new defect

[PATCH] bitten master crashes when unittest's method includes a non-ASCII encoding docstring

Reported by: Xie Yanbo <xieyanbo@…> Owned by:
Priority: critical Milestone: 0.6.1
Component: Build master Version: 0.6b2
Keywords: Cc: tony@…
Operating System: Linux

Description

If a testcase method includes an utf-8 encoding short description like this:

class Utf8DocstingTestCase(TestCase):
    def test_something(self):
        '''test utf-8 Chinese character, 测试汉字'''
        pass

Bitten will crash with:

Traceback (most recent call last):
  File "/usr/lib64/python2.5/site-packages/trac/web/main.py", line 450, in _disp
atch_request
    dispatcher.dispatch(req)
  File "/usr/lib64/python2.5/site-packages/trac/web/main.py", line 206, in dispa
tch
    resp = chosen_handler.process_request(req)
  File "/usr/lib64/python2.5/site-packages/bitten/master.py", line 130, in proce
ss_request
    return self._process_build_step(req, config, build)
  File "/usr/lib64/python2.5/site-packages/bitten/master.py", line 324, in _proc
ess_build_step
    report.insert(db=db)
  File "/usr/lib64/python2.5/site-packages/bitten/model.py", line 936, in insert
    in item.items()])
  File "/usr/lib64/python2.5/site-packages/trac/db/util.py", line 80, in execute
many
    return self.cursor.executemany(sql_escape_percent(sql), args)
  File "/usr/lib64/python2.5/site-packages/trac/db/sqlite_backend.py", line 64, 
in executemany
    args or [])
  File "/usr/lib64/python2.5/site-packages/trac/db/sqlite_backend.py", line 51, 
in _rollback_on_error
    return function(self, *args, **kwargs)
ProgrammingError: You must not use 8-bit bytestrings unless you use a text_facto
ry that can interpret 8-bit bytestrings (like text_factory = str). It is highly 
recommended that you instead just switch your application to Unicode strings.

cause sqlite does not accept the utf8 string.

My environment:

  • Bitten: 0.6b2
  • Python: 2.5
  • pysqlite: 2.5.6
  • OS: Gentoo Linux

Patch attached.

Attachments (1)

bitten_utf8_docstring.patch (803 bytes) - added by Xie Yanbo <xieyanbo@…> 15 years ago.

Download all attachments as: .zip

Change History (5)

Changed 15 years ago by Xie Yanbo <xieyanbo@…>

comment:1 Changed 15 years ago by osimons

Thanks for report.

Seems very late to deal with different variations of string when building strings for SQL execute? I think a more correct approach would be to make sure Report.items don't get populated with anything but Unicode strings. That means converting as strings are received from input (ie. xml from slave). Which I kind of thought we did, but this must have slipped through somehow (although I have not verified it myself).

comment:2 Changed 15 years ago by Xie Yanbo <xieyanbo@…>

you are right, how about this:

  • bitten/master.py

    diff -rNu Bitten-0.6b2.orig/bitten/master.py Bitten-0.6b2/bitten/master.py
    old new  
    319319                item = {'type': item_elem.name}
    320320                item.update(item_elem.attr)
    321321                for child_elem in item_elem.children():
    322                     item[child_elem.name] = child_elem.gettext()
     322                    item[child_elem.name] = child_elem.gettext().decode('utf8')
    323323                report.items.append(item)
    324324            report.insert(db=db)

comment:3 Changed 15 years ago by osimons

Thanks, feels better. A unittest would also be really nice... :-)

comment:4 Changed 11 years ago by Tony Meyer <tony@…>

  • Cc tony@… added

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
Author


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

 
Note: See TracTickets for help on using tickets.