TableError: Column is a string

**What I’m trying to do:
I am trying to capture data into my data table, but am missing something somewhere. my postal_code_2 has been instantiated, the data table column is set as text, but i keep on getting this error upon running my function:

anvil.tables.TableError: Column ‘postal_code_2’ is a string - cannot set it to a simpleObject

called from /libanvil/anvil/_server.py, line 41 called from [ServerModule1, line 47](javascript:void(0)) called from [add_account, line 52](javascript:void(0))

What I’ve tried and what’s not working:
Renamed the table column, class and input field

Code Sample:

def button_8_click(self, **event_args):
    """This method is called when the button is clicked"""
    acc_no = ""
    surname = self.surname_box.text
    initials = self.initials_box.text
    title = self.title_box.text
    full_names = self.fulle_names_box.text
    id_number = self.id_no_box.text
    cell_no = self.cell_no_box.text
    tel_no_h = self.tel_no_h_box.text
    tel_no_w = self.tel_no_w_box.text
    email_address = self.email_address_box.text
    street = self.street_name_box.text
    suburb = self.suburb_box.text
    town_city = self.town_city_box.text
    postal_code_1 = self.postal_code_box.text
    po_box = self.po_box_box.text
    po_box_suburb = self.po_box_suburb_box.text
    postal_code_2 = self.postal_code_box_2.text
    medical_aid = self.medical_aid_drop.items
    medical_aid_option = self.medical_aid_drop.items
    medical_aid_no = self.member_number_box.text
    dependant = self.dependant_box
    anvil.server.call('add_account', acc_no, surname, initials, full_names, title, id_number, cell_no, tel_no_h, tel_no_w, email_address, street, suburb, town_city, postal_code_1, po_box, po_box_suburb, postal_code_2, medical_aid, medical_aid_no, medical_aid_option, dependant)
    Notification("Account added").show()
    self.clear_inputs()

Clone link:
share a copy of your app

Welcome to Anvil!

I reckon your add_account function has the fields in a different order to the way you’re passing them.

You are passing them as positional parameters, so they must tie up exactly the other side. Maybe try using keyword arguments?

I’m going with a wild guess: the list of arguments on the client doesn’t match the list on the server side.

You are passing postal_code_2 as the 17th argument, but you are expecting it as the 18th on the server side.

Since on the client side you are passing medical_aid as 18th argument, and since medical_aid is set to a list, the server function complains when it tries to put a list in a text column.

So one way to solve the column order problem is, as @david.wylie suggested, using a dictionary instead of variables and unpacking that dictionary directly into the app_tables add_row method:

new_row_dict = {	
			'acc_no' : "" ,
			'surname' : self.surname_box.text ,
			'initials' : self.initials_box.text ,
			'title' : self.title_box.text ,
			'full_names' : self.fulle_names_box.text ,
			'id_number' : self.id_no_box.text ,
			'cell_no' : self.cell_no_box.text ,
			'tel_no_h' : self.tel_no_h_box.text ,
			'tel_no_w' : self.tel_no_w_box.text ,
			'email_address' : self.email_address_box.text ,
			'street' : self.street_name_box.text ,
			'suburb' : self.suburb_box.text ,
			'town_city' : self.town_city_box.text ,
			'postal_code_1' : self.postal_code_box.text ,
			'po_box' : self.po_box_box.text ,
			'po_box_suburb' : self.po_box_suburb_box.text ,
			'postal_code_2' : self.postal_code_box_2.text ,
			'medical_aid' : self.medical_aid_drop.items ,
			'medical_aid_option' : self.medical_aid_drop.items ,
			'medical_aid_no' : self.member_number_box.text ,
			'dependant' : self.dependant_box ,
				}
anvil.server.call('add_account', new_row_dict )

Then in your function you can do something like:

def add_account(new_row_dict ):
    app_tables.your_accounts_table_name.add_row( **new_row_dict )

:cake:

(Obviously I don’t know your function, or if you check if a record exists before adding new records)

Edit: I don’t know if this was apparent, but doing it the above way solves any problems someone might have with the order of the columns they are adding/updating.

some re-ordering and voila! thanks!