[Beta] Inconsistent behavior calling a server function from the server console

I open a server console, call a function using anvil.server.call and get a result, while directly calling the function I get a different result:

I tried to reproduce the same problem in a little app created from scratch, with branches and environments defined in a similar way, but with the new app I was consistently getting the expected result: after editing the function in the server module, it was enough to close and restart the console to get the new result with both calls.

But in the real app I can see the result of new editing only when I call the function directly. When I use , anvil.server.call it seems to be running either an old version of the function or one defined in another branch.

1 Like

Just in case you landed here and you are looking for a reason why calling the same server function would return two different results, here is why it was happening to me.

The problem was caused by two things happening at the same time:

  • I had an uplink script running on my computer that was registering a function with the same name
  • I had the Run scheduled tasks in this environment checked in the development environment (publish - environment - show advanced options - uplink keys)

ServerModule.get_releases() calls the function defined on the selected environment running on the server.

anvil.server.call('get_releases') calls the function registered by the uplink script, regardless of the selected environment.

In addition to this, which was already spooky enough, I was running that uplink only while running tests or debugging, so sometime the script was there and sometimes it wasn’t.

(Thanks @ian, I wouldn’t have figured it out by myself).

2 Likes