(possible) auto formula updating fail, when referenced column renamed,

My favorite feature of grist is when i rename a column, The formula’s referencing that column get updated with that new name automatically. So much time and frustration this has saved me!

I noticed that it is failing to update the column name in the second last line of this formula. It remains “Row_Timestamp” where as the rest of the reference’s have correctly changed to “row_timestamp_pb”

if not $Placed or not $Placed_Timestamp:
    latest = Portfolio_balance.lookupOne(order_by="-row_timestamp_pb")
    return latest.h_total_cash_pb if latest else 0
else:
    candidates = [
        p for p in Portfolio_balance.all 
        if p.row_timestamp_pb and p.row_timestamp_pb <= $Placed_Timestamp
    ]
    if not candidates:
        return 0
    snapshot = max(candidates, key=lambda p: p.Row_Timestamp)
    return snapshot.h_total_cash_pb

Its happened multiple times for me. here is another formula from the same instance.

if not $Placed or not $Placed_Timestamp:
    latest = Portfolio_balance.lookupOne(order_by="-row_timestamp_pb")
    return latest.o_total_cash_pb if latest else 0
else:
    candidates = [
        p for p in Portfolio_balance.all 
        if p.row_timestamp_pb and p.row_timestamp_pb <= $Placed_Timestamp
    ]
    if not candidates:
        return 0
    snapshot = max(candidates, key=lambda p: p.Row_Timestamp)
    return snapshot.o_total_cash_pb

I just thought I would highlight this for the devs in case its helpful.

This is a good use for ordered lookups using .find methods – see Function reference - Grist Help Center). They were also the subject of January’s webinar.

I see you already use lookupOne with order_by to find the last record. To find the nearest record below $Placed_Timestamp, you can do this:

snapshot = Portfolio_balance.lookupRecords(order_by="row_timestamp_pb").find.le($Placed_Timestamp)
return snapshot.h_total_cash_pb

This should keep columns updatable (i.e. respect renames automatically), and should also be faster!

In general, Grist is pretty good about renaming columns when they are properties of objects it recognizes (references, results of lookups). But in complex cases, like with list comprehensions or lambdas, as in your example, it can’t analyze the code deeply enough, so can’t do automatic renames.