TLDR: It looks like the getMachineTypeSelected function parameter (the argument fed to the server module call) is populated with a list with one element in it, and you are calling str() on it
So you are passing it [‘a250’] which is literally a list with one string object in it as the only item in the list.
In the table insert you are calling str() on this list, so it is making the list human readable and then putting it in the text field, so it looks like how a human would type that list in string form.
When dealing with databases of any kind in python the column types you set almost always correspond to the basic data types python uses in some way, so a ‘Text’ column holds strings, a ‘Number’ holds integers or floats etc. Anvil has some special ones that hold python objects themselves for ease of use.
More info:
https://realpython.com/python-data-types/
The text column you are writing to should give you an error if you tried to give it a list instead of a string, but you circumvented the error by turning your list into a string that looks like a list.
Does that make sense?
you can either modify your code where you are calling this function to pass in getMachineTypeSelected as a string (I’m guessing by accessing the first element in the list like list[0], if you only have a single item)
Or you can iterate over the list inside this function if you know you will always be sending it a list and the first element of that list is the only thing you want to insert.
If you are trying to insert a list of items and not just the first one, you can iterate over the list like
for one_single_machine_type in getMachineTypeSelected:
#code here that looks like your picture above but with
# 'one_single_machine_type' in place of 'getMachineTypeSelected'
…you can drop the str() around the variables you insert.
The Python language has several philosophical reasons why things are done in a certain way, because of the way it is designed. It sounds silly but in this case, the error reporting is incredibly verbose and descriptive and will help you code.
One of the core ideas in python is to try something, and let it fail (“It is better to seek forgiveness than ask permission”)
If instead of ‘making sure what gets put into a text column is a string’ you ran the program, it would have given you this error:
anvil.tables.TableError: Column 'Type' is a string - cannot set it to a simpleObject
Learn more about Data tables
<running on the server>
called from /libanvil/anvil/_server.py, line 41
called from ServerModule1, line 25
called from Form1, line 16
Which if you read carefully, is actually a condensed version of everything I just wrote.
(The real TLDR)
