Error when querying database

I’d like to return all rows in my database that fulfill the following criteria:

return app_tables.feedback.client_readable(q.all_of(cardstart=cardstart_arg, visible=True, fixed_in_update=None))

When I do this, I get the following error that doesn’t really help me:

TableError: Invalid arguments: ‘[#anvil.dispatcher.types.ValueType{:type “anvil.tables.query.all_of”, :value {:args , :kwargs {:visible true, :cardstart “3fesf sef sef se f”, :fixed_in_update nil}}}]’. View queries can only restrict column values by simple equality.

What am I doing wrong? :thinking:

Hi @tomka!

client_readable exists to let you restrict the view onto a table using an equality. I assume you want to restrict the view to all rows whose cardstart column contains cardstart_arg? In that case, you can do this:

return app_tables.feedback.client_readable(
  cardstart=cardstart_arg
).search(
  visible=True, fixed_in_update=None
)

Generally speaking, you should use client_readable and client_writable to restrict the view, but then use search on that view to make complex queries.

We’ll consider this a bug report against that error message’s usefulness :wink:

1 Like

That is exactly what I wanted to do. Thanks a bunch, @shaun !

1 Like

While I have your attention, @shaun : Now I get the following error (The line where it occurs is not specified.):

AttributeError: ‘LiveObjectProxy’ object has no attribute ‘search’

Are you able to share a clone link for your app? (Gear menu -> Share App -> Share your source code and data with others)

Here’s an app where I’ve implemented my solution and successfully returned the correct set of rows.

https://anvil.works/build#clone:WCTHDKHWBORFAXMK=ZD3SCOVS2QXF4UTERJUTCTUD

1 Like

Works now! The problem was that I was calling .search() again on the client-side-object, so it was basically:

app_tables.feedback.client_readable(
  cardstart=cardstart_arg
).search(
  visible=True, fixed_in_update=None
).search()

Which of course makes no sense. Thanks again for the fast help, @shaun !

1 Like