Trouble with search iterators

I am working with a form that has a data table in it like :

In the form I am calling the server module when the search button is pressed and passing the text of the search field :

self.repeating_panel_1.items = anvil.server.call('search_truckloads',self.text_box_search.text)

in the server module I have this :

@anvil.server.callable
def search_truckloads(query, **event_args):
  thisuser=anvil.users.get_user()
  thislocation=thisuser['defaultLocation']
  if thislocation is None:
    result = app_tables.truckloads.search()
  else:
    result = app_tables.truckloads.search(CRCWarehouse=thislocation)
  if query:
    result = [
      x for x in result
      if query in x['inboundREF']
      or query in x['outboundREF']
      or query in x['Carrier']
      or query in x['DriverName']
    ]
  return result

It will return a result when there is no value in the field (thus query is empty so it skips the for ‘x for x…’
When I have a value in the field, it throws :
TypeError: ‘NoneType’ object is not iterable at [ServerModule1, line 20](javascript:void(0)) called from [ServerModule1, line 19](javascript:void(0)) called from [Home, line 40](javascript:void(0))

I have done a pprint(result) right before the referenced line and it shows :
<LiveObject: anvil.tables.SearchIterator>

what am I missing?

what am I missing

If I’m following you correctly, you’re looking for the query value to be in any of the columns of your data table? If yes, I would probably move that logic into the app_tables query itself something like this:

app_tables.customers.search(q.any_of(Name=q.ilike(“%”+str(query)+“%”),
Email=q.ilike(“%”+str(query)+“%”)))

To my eyes it seems that you have None in your data tables somewhere.

When you ask:

"my_string" in None

you get the “None Type is not iterable” error.

You would have to deal with Nones by converting them to strings or modifying the logic in some way.

Apologies if the formatting looks odd, I’m on my phone.

1 Like

Had the same problem and found this solution. Hope it helps.