Looking for some help understanding why this argument is not valid

What I’m trying to do: I have a server module called server module_1 which at this stage has only one simple deffinition

def add_name(names):
user = anvil.users.get_user()
app_tables.answers_from__user.add_row(Name=names)

answers_from__user has a column ‘name’

When I call this function using

anvil.server.call(‘add_name’,self.names)
I get this error.
AttributeError: ‘questionForm’ object has no attribute ‘names’ at [Homeform.questionForm, line 55](javascript:void(0))

I cant understand why it refers to questionForm when I’m calling a function in server module.I am calling the function from within the questionForm,but can’t figure out why it gives the error and does not accept the argument ‘names’.

What I’ve tried and what’s not working:

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 

Clone link:
share a copy of your app

I’ve bolded that part that is causing your issue. The self in self.names refers to your form, and it’s trying to access a names property on that form. The error is saying that the form doesn’t have a names property.

Without the rest of the form code it’s impossible to say what you should be doing instead.

Thank you for looking at it

Heres the code if you wouldn’t mind taking a look

https://anvil.works/build#clone:GM4JZMBNTIHXNHB5=4DXG6QP27OJ4LCPJ2CSAHSUV

I just looked - nowhere in your “questionForm” is there a definition of “self.names”.

At a guess, are you trying to pass the names in your text area control called “text_area_1”?

If so, you need to pass “self.text_area_1.text”.

Python will look for a class property called “names”, either in the form of a control or a property you yourself have defined. As it is not finding one, you are seeing that error.

1 Like

No, I’m trying to call the definition in server module_1 as per line55 questionForm

In your anvil.server.call() you are passing a parameter called self.names, ie you are sending that to the server function from the form.

It doesn’t exist in the form, hence the error.

If you manually define self.names somewhere in your form code before you make the server call, the error will go away which will prove the point.

Can you please explain what you are trying to achieve? That might help me to help you better.

Thanks for looking into this for me,I appreciate your help.
I am trying to have the definition in the server module, add names to answers_from__users table,and am trying to call the function which is in the server module (that I think should do the saving) from line 55 in questionForm.
Does this make sense?

As @david.wylie and @jshaffstall have pointed out, you are passing an argument to your add_name function that hasn’t been defined. What are you trying to pass into your function? In other words, what are you expecting self.names to be?

Also, in that cloned app, you’ve defined a server function called add_name, but on the client, you are trying to call a function called add_names.

1 Like

Sorry for all the confusion,I am new to all of this and trying my best to be clear but a large part of the problem is my lack of competence in both anvil and python
Anyhow…
I have changed the code slightly so the add_name function is called when text is entered in text_area_1
I have a data table called answers_from__user and in that table I have a column called name,
I am trying to get the input in text area_1 to be saved to name in answers_from__user

Hope this is a little clearer

Then I think @david.wylie’s original answer is what you are after: Looking for some help understanding why this argument is not valid - #6 by david.wylie

1 Like

Thanks David
It’s a long haul for me,but the ride is enjoyable

1 Like