To_csv on search iterator ignores order arguments

I have a few situations where I convert a table search to a dataframe using the to_csv method.

However, I am noticing that this ignores the order argument I’m passing it. Instead to_csv returns in the default order (approximately the order of insertion).

Can to_csv be made to use the order arguments we pass it, so its returned values are consistent with the search?

Clone link demonstrating the behavior:
https://anvil.works/build#clone:CQDHXX42V7ZAIC4E=A2LOKBOST7FRH34BXJJIWRAV

1 Like

Ha! to_csv() ought to raise an error if you provide any arguments at all :slight_smile:

However, you can also call to_csv() on a search iterator. So you can do:

app_tables.my_table.search(tables.order_by('foo')).to_csv()

…to get the result you want.

4 Likes

What witchcraft is this??

1 Like

My problem is that I AM calling to_csv on the search iterator and my order argument is ignored!

Aha! This is why code samples are useful; I answered before cloning your app(!) and assumed that “Can to_csv be made to use the order arguments we pass it?” meant you were passing those arguments to to_csv().

Anyway, now reproduced, and this is definitely a bug! Moving to Bug Reports.

2 Likes