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 #1128 (closed defect: wontfix)

Opened 13 years ago

Last modified 12 years ago

turbogears.redirect() incorrectly used

Reported by: alain.spineux@… Owned by: anonymous
Priority: normal Milestone: 1.0b2
Component: TurboGears Version: 1.0b1
Severity: normal Keywords:
Cc:

Description

Tutorial and code generated by quickstart use turbogears.redirect() like this

raise turbogears.redirect(url)

but regarding the function source, the correct use is just a call to the function

turbogears.redirect(url)

The source of the function in /site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py is

def redirect(redirect_path, redirect_params=None, **kw):
    """Redirect (via cherrypy.HTTPRedirect)."""
    raise cherrypy.HTTPRedirect(
                    url(tgpath=redirect_path, tgparams=redirect_params,
**kw))

of course the current use is working but it's usage is not correct.

It's better to show the raise in the source code to let the user keep in mind the flow of the program is changing. The simple function call will hide the flow disturbance.

Changing the raise by a return in the function will do the trick

Then I suggest to replace the function definition by :

def redirect(redirect_path, redirect_params=None, **kw):
    """A shortcut for cherrypy.HTTPRedirect."""
    return cherrypy.HTTPRedirect(
                    url(tgpath=redirect_path, tgparams=redirect_params,
**kw))

for more info look

 http://groups.google.com/group/turbogears/browse_frm/thread/35033ba7f3126d9a/01d3f86543708a4e#01d3f86543708a4e

Change History

comment:1 Changed 13 years ago by jorge.vargas

  • Component changed from unassigned to TurboGears
  • Milestone set to 1.0b2

comment:2 Changed 13 years ago by jnf

No matter if one agrees, that the explicit "raise" in TG users' program code is better style (I don't), this change would break the interface and therefore would break perfectly working TG apps with no need for it.

comment:3 Changed 13 years ago by alain.spineux@…

To not break working TG apps, one can declare turbogears.redirect() as deprecated and define a new function like turbogears.HTTPRedirect() and recommend it's use in tutorial and in quickstart's auto generated code.

def HTTPRedirect(redirect_path, redirect_params=None, **kw):
    """A shortcut for cherrypy.HTTPRedirect."""
    return cherrypy.HTTPRedirect(
                    url(tgpath=redirect_path, tgparams=redirect_params,
**kw))

The new function could use a raise or a return (this is not my choice).

comment:4 Changed 13 years ago by jorge.vargas

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

see the reason in

 http://tinyurl.com/eaxf8

Note: See TracTickets for help on using tickets.