Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2267 (closed defect: fixed)

Opened 10 years ago

Last modified 9 years ago

Error on object dispatch with unicode paths

Reported by: droggisch Owned by:
Priority: normal Milestone: 2.1rc1
Component: TurboGears Version: trunk
Severity: normal Keywords:


When dispatching a url like


TG2 bails out because it tries to find an attribute with the name u"äö" in the controller hierarchy. This fails, because python 2.X doesn't allow unicode function name literals.

But this might still be a valid url, in case a default-method is given and captures the remaining path components.

The attached patch fixes the issue, together with another one I will create a different ticket for.


tg2.patch Download (4.8 KB) - added by droggisch 10 years ago.

Change History

comment:1 Changed 10 years ago by chrisz

Actually it should be even possible to have controller names with non ascii chars, regardless of the fact that they cannot be used in method names, using the trick mentioned in  this thread.

comment:2 Changed 10 years ago by droggisch

Seems so, yes

#-*- coding: utf-8 -*-

class MyController(object):
    def i_want_umlauts(self):

setattr(MyController, u'ich-möchte-umlaute'.encode('utf-8'), MyController.i_want_umlauts)

So I propose to change the code that it does an encode('utf-8') for parts.

comment:3 Changed 10 years ago by mramm

  • Milestone changed from 2.0rc1 to 2.1

Sure this would be nice, and I like the idea on one level.

On the other hand, we do have a unicode capable URL system, Routes, and I think that this may be too big of a change to fit in before 2.0, since we're in a hard feature freeze.

I hope to release 2.0rc1 and move 2.0 development to a branch this week, at which point we can talk about moving this into trunk.

comment:4 Changed 10 years ago by droggisch

Ok, but then the patch as is can be applied? Because that fixes an actual bug, and doesn't add a feature.

Changed 10 years ago by droggisch

comment:5 Changed 10 years ago by percious

I'm not entirely sure what bug the patch is fixing, and I don't think we should add this to 2.x (maybe 3.x when we support Python 3)

I think there are better methods for handling this, such as using lookup() and calling a separate controller, or handling the unicode value internally.


comment:6 Changed 10 years ago by droggisch

I don't understand what you mean by "lookup()"

I'm all ears for a different solution to the following problem: make a restful url-scheme like  http://myhost/users/<username> where <username> can contain any utf-8 character you like.

This is what's happening for us, and which is breaking the dispatch. And I fail to see where Py3K comes into this - it's not about unicode-literals for known controller methods - that's working. Default-dispatch isn't.

Either we want to treat remaining path elements as parameters equivalent to GET/POST-params - which the patch allows - or we don't, and then we need a different way of doing this. I'm open for suggestions.

comment:7 Changed 10 years ago by mramm

  • Version changed from 2.0b7 to trunk

Agreed, this should be fixed in the 2.1 branch.

comment:8 Changed 10 years ago by droggisch

I think it is already in the 2.0-branch. This surprised me :) I guess that happened when I applied #2268. Sorry for that, it was not with the intent to subvert this discussion process here.

Given that the change is already in there for a while, didn't cause any harm, and is only a fix, not a feature - do you mind keeping it in there?

comment:9 Changed 10 years ago by percious

  • Status changed from new to closed
  • Resolution set to fixed

I believe this works fine in 2.1 and there is even a test for it:  http://bitbucket.org/turbogears/tg-dev/src/tip/tg/tests/test_tg_controller_dispatch.py#cl-397


comment:10 Changed 9 years ago by percious

  • Milestone changed from 2.1 to 2.1rc1
Note: See TracTickets for help on using tickets.