171: Error on creating new review request when accessing authentication SVN

mhorva******@gmai***** (Google Code) (Is this you? Claim this profile.)
chipx86
chipx86
Aug. 28, 2007
I'd like to create a new review request, but when I just see this error:

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in
get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "/reviewboard/djblets/auth/util.py" in _checklogin
  45. return view_func(request, *args, **kwargs)
File "/reviewboard/reviews/views.py" in new_review_request
  86. fields[repo.id] = repo.get_scmtool().get_fields()
File "/reviewboard/../reviewboard/scmtools/models.py" in get_scmtool
  42. return cls(self)
File "/reviewboard/scmtools/svn.py" in __init__
  16. self.client.set_default_username(repository.username)

  TypeError at /r/new/
  cannot return std::string from Unicode object

The error message says all ...
chipx86
#1 chipx86
  • -Priority-Medium
    +Priority-Critical
    +Component-SCMTools
chipx86
#2 chipx86
Not sure if this is really our bug or pysvn's. Can you tell me what username you're
using, or more specifically, if the username has any non-alpha-numeric characters in it?
  • +NeedInfo
#3 jan.s******@gmai***** (Google Code) (Is this you? Claim this profile.)
I'm getting the same exact error. To me it looks like it is related to the svn
credentials cache - creating reviews works when you've already checked out a
repository under a user account currently running the reviewboard app.

Try getting rid of the credentials in your repository setup and try again.
#4 mhorva******@gmai***** (Google Code) (Is this you? Claim this profile.)
Well, if I fill in the user credentials in /reviewboard/scmtools/svn.py (line 16 to 18), it works.

But this wouldn't be a solution.

Anyway, it looks to me like a bug of reviewboard, not pysvn.

Cheers, Max!
#5 John.L.H*********@gmai***** (Google Code) (Is this you? Claim this profile.)
The bug appears to be with pysvn.  pysvn.Client cannot handle the Unicode strings
Django is returning although the exception message appears to originate in the
Py:String class (search for "cannot return std::string from Unicode object") [1].  

The bug can be fixed by forcing the username and password to a non-Unicode encoding
before passing them to the pysvn client.  Here is how I recreated the issue:

>>> import pysvn
>>> client = pysvn.Client()
>>> client.set_default_username(u'huddlej')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot return std::string from Unicode object
>>> client.set_default_username(u'huddlej'.encode('utf-8'))
>>>

My guess is since Django merged the Unicode branch all Review Board settings are
being returned as Unicode.  It would be interesting to know if anyone using a
pre-Unicode-merge Django version is having the same trouble.

[1] http://inkscape.modevia.com/doxygen/html/classPy_1_1String.php
#6 John.L.H*********@gmai***** (Google Code) (Is this you? Claim this profile.)
Attached is an example patch if that helps...
  • +
    Index: reviewboard/scmtools/svn.py
    ===================================================================
    --- reviewboard/scmtools/svn.py	(revision 865)
    +++ reviewboard/scmtools/svn.py	(working copy)
    @@ -14,9 +14,9 @@
             SCMTool.__init__(self, repository)
             self.client = pysvn.Client()
             if repository.username:
    -            self.client.set_default_username(repository.username)
    +            self.client.set_default_username(repository.username.encode('utf-8'))
             if repository.password:
    -            self.client.set_default_password(repository.password)
    +            self.client.set_default_password(repository.password.encode('utf-8'))
     
             self.uses_atomic_revisions = True
     
chipx86
#7 chipx86
Is this still problematic? The change has been in Review Board for a little while now.
  • +chipx86
#8 John.L.H*********@gmai***** (Google Code) (Is this you? Claim this profile.)
It's working for me.  The str() change seems to have done the trick.  Thanks!
chipx86
#9 chipx86
Awesome, thanks!
  • -NeedInfo
    +Fixed