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 #554 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

When using @error_handler cherrypy.request.input_values is resetted

Reported by: michele Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TurboGears Version:
Severity: major Keywords:
Cc:

Description

If you are using error_handler in this way:

    @expose(template=".templates.save")
    @validate(form=comment_form)
    @error_handler(index)
    def save(self, name, email, comment, notify=False):
        comment = Comment(name, email, comment)
        return dict(comment=comment)

if there are errors the form is redisplayed with empty fields.

This way works as excepted:

    @expose(template=".templates.save")
    @validate(form=comment_form)
    def save(self, name, email, comment, notify=False, tg_errors=None):
        if tg_errors:
             return self.index()
        comment = Comment(name, email, comment)
        return dict(comment=comment)

But I also expect the first method (that's nicer) to work right.

I don't have enough time to look into what's going on.

Change History

comment:1 Changed 13 years ago by simon

Can't reproduce. Would you mind trying with r>747.

comment:2 Changed 13 years ago by michele

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

Working fine now, probably also before your changes, I tried with another project and it's working so it could be my fault as I'm a bit off synced these days.

Thanks anyway. :)

comment:3 Changed 13 years ago by michele

  • Status changed from closed to reopened
  • Resolution worksforme deleted

I think I've found the problem.

Step to reproduce:

Suppose to have this method

@turbogears.expose()
@turbogears.validate(form=form)
@turbogears.error_handler(index)
def save(self, name, age):
    print "input_values: ", getattr(cherrypy.request, "input_values", None)
    ...

That's the output I get in the console:

input_values:  {}

But if use:

@turbogears.expose()
@turbogears.validate(form=form)
@turbogears.error_handler(index)
def save(self, **kw):
    print "input_values: ", getattr(cherrypy.request, "input_values", None)
    ...

all works as expected:

input_values:  {'age': 23, 'name': 'michele'}

comment:4 Changed 13 years ago by simon

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

Fixed in r767.

Should have been copying (of a dict) instead of assignment.

Note: See TracTickets for help on using tickets.