Unexpected keyword argument on raise_event

Hello,

I’m trying to set up an event handler on repeating panel template. But I got this error : “TypeError: delete_project() got an unexpected keyword argument ‘event_name’”. While raise_event effectively has event_name as an argument.

Could someone help me ?

That’s the link to the app : Anvil | Login

Thank you !

I haven’t cloned your app, but I suspect your handler is missing the event_args argument. That’s described in the docs at:

1 Like

I’m not very sure.

That’s the method which is called with click event :

def delete_goal(self, **event_args):
    if confirm("Are you sure you want to give up the goal {}?".format(self.item['BigGoalHeadline'])):
      self.parent.raise_event("x-delete-goal", goal=self.item)

This method is supposed to trigger its parent object which will call ‘delete_goal’(parent code). And delete_goal requires an argument goal which is the goal to delete.
So my event’s name is ‘x-delete-goal’, which is the first argument of raise_event and ‘goal’ represents the argument required by ‘delete_goal’ in parent code.

delete_project needs the event_args

def delete_project(self, goal, **event_args):
    ...

All event handlers get event_args passed to them. These include the event_name and the sender, as well as any custom event args added using raise_event (in your case goal).

An alternative way to write the same event handler might be

def delete_project(self, **event_args):
    goal = event_args["goal"]
    ...

(assuming you only ever use the function as an event handler and never call it directly)

(anvil’s event_args is the same thing as keyword arguments)

So I solved my problem. The functions that handle the events must have **event_args as an argument, which I didn’t do when I created the events.

(that’s what @owen.campbell said on his first answer :slight_smile:)

2 Likes