Hi all, I just found out some weird thing working with @with_transaction, and was wondering whether I'm doing something wrong or it's expected Python behavior.
I have a class method that receives some parameters. In the method, I have a @with_transaction function to write things on the database, using the method's input parameters (through a closure). It works fine, unless the function itself has some code that writes to a variable named like one of the parameters. In this case, I get an unbound local variable error when trying to use the input parameter. I guess this is just standard Python closures behavior, but wanted to check with you guys anyway: def save_stuff(self, t_action, t_id, t_name): @with_transaction(self.env) def do_save_stuff(db): cursor = db.cursor() if t_action == 'ADD': # "Offending" row t_id = self.get_next_id() cursor.execute(""" INSERT INTO stuff (id, name) VALUES (%s,%s) """, (t_id, t_name)) else: # I get an error here for unbound local t_id variable # unless I comment out the "t_id = self.get_next_id()" row above cursor.execute(""" UPDATE stuff SET name = %s WHERE id = %s """, (t_name, t_id)) Ciao, Roberto -- You received this message because you are subscribed to the Google Groups "Trac Development" group. To post to this group, send email to trac-dev@googlegroups.com. To unsubscribe from this group, send email to trac-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/trac-dev?hl=en.