suds.sax.text.Text objects with unicode cannot be encoded when used in lists

Bug #1100758 reported by Kasper Dupont
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
suds (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

When a unicode string received from a python-suds call is saved in a django database an exception is generated in this line of /usr/lib/python2.7/dist-packages/django/db/backends/util.py:
            logger.debug('(%.3f) %s; args=%s' % (duration, sql, params),

This appears to be a bug in the suds.sax.text.Text class used inside of params. I reproduced the problem in a few lines of code:
#!/usr/bin/env python
from suds.sax.text import Text
v=Text(u'Bl\xe5')
print v
print [ v ]

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: python-suds 0.4.1-2ubuntu1
ProcVersionSignature: Ubuntu 3.2.0-35.55-generic 3.2.34
Uname: Linux 3.2.0-35-generic i686
NonfreeKernelModules: nvidia
ApportVersion: 2.0.1-0ubuntu17.1
Architecture: i386
Date: Thu Jan 17 13:09:54 2013
EcryptfsInUse: Yes
InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Release i386 (20110427.1)
MarkForUpload: True
PackageArchitecture: all
ProcEnviron:
 LANGUAGE=en_US:en
 TERM=screen
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: suds
UpgradeStatus: Upgraded to precise on 2012-05-08 (253 days ago)

Revision history for this message
Kasper Dupont (ubuntu-launchpad-feb) wrote :
Revision history for this message
Kasper Dupont (ubuntu-launchpad-feb) wrote :

I took a look on the source of suds.sax.text.Text and tried to remove everything unrelated to the bug. I found that the following lines of the suds.sax.text.Text implementation is everything necessary to reproduce the problem.

class Text(unicode):
    def __repr__(self):
        s = [self]
        return ''.join(s)

I haven't spotted the bug in those lines of code. Does anybody else spot the bug right away?

Revision history for this message
Kasper Dupont (ubuntu-launchpad-feb) wrote :

Found the bug. From the documentation on __repr__ http://docs.python.org/2/reference/datamodel.html
"The return value must be a string object."

However suds.sax.text.Text returns unicode. Adding .__repr__() appears to fix the problem. So replace
        return ''.join(s)
with
        return ''.join(s).__repr__()
and the problem goes away.

Changed in suds (Ubuntu):
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Scott Talbert (swt-techie) wrote :

I believe this is no longer an issue because it doesn't occur under Python 3 and Python 2 is EOL.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.