Am I using get_by_id wrong?

I’m trying to get a row from my database using
app_tables.my_table.get_by_id(app_id)

I keep getting None returned, and I’m only trying to get row 1.

I’ve tried:
app_tables.my_table.get_by_id(1)
app_tables.my_table.get_by_id(“1”)
app_tables.my_table.get_by_id(id=1)
app_tables.my_table.get_by_id(id=“1”)
app_tables.my_table.get_by_id(ID=“1”)

I get either none or various errors.
And yes the server call is working because I can use simply .get(name=name) to get the column. But that’s not a long term solution.

I just realized a very obvious workaround.

app_tables.my_table.get(id=app_id) is working fine.

However it’s still bothering me that the get_by_id function isn’t working.

That’s wrong. The ID column is the postgres row id (of format [X,Y]). If you just want to get the first row in a data table you can use:

app_tables.my_table.search()[0]

Note that order isn’t guaranteed (unless you pass an order_by argument).

If you want to get a row ID, it can be retrieved from a row object using get_id.

my_row = app_tables.my_table.search()[0]
row_id = my_row.get_id() # i.e. "[123, 123]"

# later on
my_Row = app_tables.my_table.get_by_id(row_id)
3 Likes

Wow ok I guess I was way off, thanks that works!