Get_by_id Documentation

** Question **
Please send me the link to the documentation telling me the answer to this question:
What happens when the row id is not in the table?
app_tables.tablename.get_by_id(id)
What I’ve tried and what’s not working:
Searching google and anvil.works docs
What I found:

get_by_id(id) → row

Get the matching row from this data table, by its unique ID

Anvil Docs | Using Data Tables from Python

I think that is all. Can you please explain clearly what you want help with?

Hi,
I am sending a row_id from the client to the server. I want to check that the id is valid. What happens when it is not valid? I could not find this information in the documentation…
regards
Ben

This is one of those questions that’s super easy to test yourself, just by writing code that uses an invalid id and printing the result. Off the top of my head, I’d assume it returns None (and have written code based on that assumption), but I’m not sure where I read that.

You will get an error that no row was found with this id (Don’t remember the exact words though)
As simple as that. You can use the try/except blocks to handle this situation

Yes, once I find the answer, how can I add it to the docs?
It would be super super easy to find the answer in the docs then.

For now, I think the recommendation is to add it to this request thread: Anvil Documentation Suggestions [ON-GOING]

1 Like

For anyone looking for the answer:

If the id is not found,

app_tables.tablename.get_by_id(uid)

returns

None
3 Likes