Store a nested disctionary in a simple object column
Works with normal Anvil Tables but does not store the nested dictionary contents
using accelerated tables when it is assigned in a server function
@anvil.server.callable
def copy_preferred(uid):
cand=app_tables.candidates.get(uid=uid)
attrs=cand['attributes']
preferred_dict={p:cand['preferred'].index(p)+1 for p in cand['preferred']}
attrs['preferred']=preferred_dict
cand['attributes']=attrs
Works fine if function is called only on the server, but not when called from the client, i.e., the attributes field is not updated with the revised nested dictionary.
All works fine without accelerated tables though.
Any ideas?
Gautam
In accelerated tables you need to send the row to the server in order for the update to propagate to the client.
@anvil.server.callable
def copy_preferred(cand):
attrs=cand['attributes']
preferred_dict={p:cand['preferred'].index(p)+1 for p in cand['preferred']}
attrs['preferred']=preferred_dict
cand['attributes']=attrs
This does not seem to be the problem; even if uid is not passsed, i.e., hardcoded in the server, the database is not updated for columns having a nested dictionary.
Issue seems to be with nested simple objects perhaps?
Gautam
Are you able to create a minimal working example that demonstrates the issue.
(I tried creating one from the snippet and it worked as expected)
Proving difficult to reproduce! Must be some difference in pass by reference
or related. Anyway I’ve fixed the application by avoiding nested dictonaries.
When I get time I may debug further - same code with and without accelerated
tables was behaving differently, that’s for sure.
Since my app is in production with hundreds of users, will get back to this eventually … for now lights need to be on, and faster because of accelerated tables , so that’s working for now.
Thanks anyway,
Gautam