[Fixed] Odd behavior with a custom dictionary in Skulpt

I have a situation where I normally pass in a dict, but in a certain context I want to pass in a custom dict that will load values via server calls. I’ve written the custom dict, but am getting an odd sort of interruption of the code. Skulpt is clearly not tolerating the delay of the server call.

What Should Happen

Code like this accesses an element of the custom dict:

self.label_2.text = Cache.media['foo']

The custom dict itself will, if it does not have an entry for the key ‘foo’, make a server call to get the entry. After that it caches it so it gets returned without the server call.

I have some debug output in place, and the output I expect to see is:

Calling Fetch
Fetching media for foo      -- this is just before the server call in the custom dict
get_media called for foo   -- this is printed in the server call
get_media fetched URL    -- this is also printed in the server call
Got foo                              -- this is after the server call returns in the custom dict
Done calling Fetch

What Actually Happens

Calling Fetch
Fetching media for foo
KeyError: foo   
at Cache, line 41 -- this line of code is after the server call should have returned
  called from Form1, line 16
get_media called for foo -- yet the server call seems to happen after that
get_media fetched URL

There seems to be some level of asynchronous behavior going on in this particular situation. This goes way beyond my knowledge of how Skulpt and Javascript work to identify why it’s happening or how to fix it.

Here’s a clone that provides a minimum repeatable example:Anvil | Login

In Form1’s init method, you can test the functionality of the custom dict without the server call by commenting out line 17. That works fine. With line 17 uncommented, the server call is made and the behavior is seen.

If this is just the way Skulpt works, I can use a different mechanism than the custom dictionary for this special context. I’m hoping, though, that there’s an easy fix for this.

1 Like

Maybe related to this one?

Maybe? I don’t actually get the SuspensionError. The custom dict is constructed fine, it’s the call to key in customdict that’s having issues.

But it might very well be the same sort of issue with blocking code having some sort of timeout on the Javascript side. I don’t know nearly enough about Skulpt to know how it handles that sort of thing.

Moved to bug reports. Thanks for reporting.

edit - yes this is a clear bug in the skulpt mechanism for the in operator.
We’ll get that fixed and should go live for you soon.
I’ll update this thread when that happens.


@stefano.menci - fyi that dict(list(user)) solution in the other thread is now no longer necessary - you can just call dict(user) and will no longer get a SuspensionError.
But yes - you’re correct - this bug is in the same family of bugs as the SuspensionError.

2 Likes

That should now be fixed

Confirmed, thanks so much!

1 Like

Is this broken again with the drop of the beta editor? I’m back to seeing similar behavior to before.

Looks like i confirmed the fix to soon - i’ll undo the un-fixed title when it gets re-fixed.

edit - that’s now fixed again :+1: