Possible accelerated tables error: `ValueError: dictionary update sequence element #0 has length 13; 2 is required`

What I’m trying to do:
print a dict for test purposes in server code

Error seems to be related to accelerated tables, as didn’t do this when not enabled.

ValueError: dictionary update sequence element #0 has length 13; 2 is required

  • at AccountsServerModule, line 25
  • called from /home/anvil/.downlink-sources/downlink-2023-07-15-08-18-50/anvil/_server.py:1359
  • called from Accounts, line 17
  • called from Frame, line 24
  • called from StartupModule, line 12
  • called from StartupModule, line 14

Code Sample:

@anvil.server.callable(require_user=True)
def get_account_org():
  org = anvil.server.session['current_org']
  account = app_tables.org_accounts.search(account_org = org)
  print(dict(account))
  return account

Line 25 is my print line.

any ideas?

You’re trying to dict the return from a call to search, which is an iterator of rows.

You probably want to dict the first row.

If you know there is only one row you might want to use get instead of search.

Note on the error:
The 13 here is likely the number of columns in the row. Dict is trying to take the sequence you give it and turn into a dictionary. You’ve given it an iterator, It gets to the first element and sees if it is like a key value pair, an element of size 2, but found an element of size 13, so it gives up.

1 Like

very true! I had commented out part of the code and switched on accelerated tables so assumed it was that! thank you.

1 Like