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 #1389 (closed defect: invalid)

Opened 12 years ago

Last modified 10 years ago

tg_error mangling *arg and **kw

Reported by: ldng Owned by: chrisz
Priority: normal Milestone: 1.0.x bugfix
Component: TurboGears Version: 1.0.2
Severity: normal Keywords: needs confirmation



I have a form which can be accessed through two url :

  • www.example.com/item/create
  • www.example.com/item/edit/45

create was defined as is :

  • def create(self, *args, kw)

and edit was an alias to create:

  • edit = create

In the body I am testing for args length to know if I need to populate the form or not.

While adding error handling I think I came across a bug (not sure though), when I add tg_error=None to the definition of create:

  • def create(self, tg_error=None, *args, kw)

when accessing www.example.com/item/edit/45 I don't get a populated form as I used to, but instead an empty form that has passed through valdation. I can tell because of the error messages for missing fields.

It looks like a bug to me.


bug.tar.bz2 Download (91.0 KB) - added by ldng 12 years ago.

Change History

Changed 12 years ago by ldng

comment:1 Changed 12 years ago by ldng

Added a quickstarted sample.

/edit_ok/7 get the data to prefill the form /edit_fail/7 doesn't.

comment:2 Changed 12 years ago by faide

  • Milestone changed from 1.0.3 to 1.1

comment:3 Changed 11 years ago by faide

  • Milestone changed from 1.1 to 1.1.1

comment:4 Changed 11 years ago by faide

  • Milestone changed from 1.6 to 1.5

comment:5 Changed 10 years ago by Chris Arndt

  • Owner changed from anonymous to Chris Arndt
  • Keywords needs confirmation added
  • Milestone changed from 1.5 to 1.0.x bugfix

Has anybody ever tried to confirm whether this is valid? Or has it been always just shifted to the next milestone? I'll check this for the next 1.0. maintenance release.

comment:6 Changed 10 years ago by Chris Arndt

  • Owner changed from Chris Arndt to chrisz

comment:7 Changed 10 years ago by chrisz

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

I don't think this is a bug, but a misunderstanding of how Python *args work. If you define your method with

def create(self, tg_error=None, *args, **kw) 

and then call /create/45, this is translated to create(45) and this will result in tg_error=45 and args=[]. You probably thought that args should be [45] but this is not the way how it works. To solve this, define your method like this:

def create(self, id=None, tg_error=None) 

And then instead of checking for len(args)==1 and using args[0], check for id is not None and then use id.

Note: See TracTickets for help on using tickets.