Issues with Uplink

Hi, I’m having some issues with my uplink code. I am fairly certain I ran similar uplink scripts in the past, and they’ve worked fine. Could you please check this for me?

Or maybe you’ll see what I am doing wrong below.
This is my uplink code:

import anvil.server
import anvil.users


def main():
    anvil.server.connect('...')
    anvil.users.login_with_email("...", "...")

    execs = anvil.server.call('api_executive_read')

    for exec in execs:
        print(exec['cik'])
    

if __name__ == '__main__':
    main()

This is the very simple server function I am trying to call:

import anvil.server

from ..crud import create_executive
from ..crud import read_executive
from ..custom_logger import log


@anvil.server.callable(require_user=True)
def api_executive_create(data: dict):
    """Data should be a dict with the following schema:
    {cik: int, first_name: str, last_name: str, other_names: str}
    """
    log(msg=f"Adding executive {data}")

    return create_executive(data=data)


@anvil.server.callable(require_user=True)
def api_executive_read(**filter):
    return read_executive(**filter)

This is the error message I keep seeing:

anvil._server.AnvilWrappedError: anvil.server.call() expects atleast 1 argument

Thank you! Maybe it is something obvious that I keep overlooking!

I don’t see any obvious issue with your code.
Have you tried passing some arguments into server.call, just to check whether **filter actually requires input?

It shouldn’t. This might just be a side effect of Anvil’s serialization/deserialization process.

Or to remove **filter from the function signature?

Hi, thank you for your quick reply. Yes, I’ve tried both (i.e. passing some args as well as removing the **filter altogether but nothing seems to have worked.

The uplink connection appears to be okay. I see my connection in the logs. I tried some print statements in the server function, and there’s nothing in the logs (which makes sense since it seems that the actual call of the function is failing).

I ran the following script on May 30, and it worked fine. When I try to run that now, I get the same error.

import pandas as pd
import anvil.server
import anvil.users

anvil.server.connect('...')
anvil.users.login_with_email("...", "...")

sec_exec_names = (
    pd.read_csv("SECExecNames.csv")
    .dropna(subset=["cik"])
    .assign(
        cik_int=lambda df: df["cik"].astype(int),
        name_list=lambda df: df["Exec Names"].str.split(" "),
        first_name=lambda df: df['name_list'].str[1],
        last_name=lambda df: df['name_list'].str[0],
        other_names=lambda df: df['name_list'].str[2:].str.join(" "),
    )
)

for row in sec_exec_names.itertuples():
    response = anvil.server.call(
        "api_executive_create",
        data={
            'cik': row.cik_int,
            'first_name': row.first_name,
            'last_name': row.last_name,
            'other_names': row.other_names,
            'data_source': 'SECExecNames.csv from Josef Svenda',
        }
    ) 

    print('Response:', dict(response))

Maybe the entire traceback will help? This includes a keyword arg in the function call.

Traceback (most recent call last):
File “H:\My Drive\projects\jan_svenda\ceo_cfo_database\scripts.venv\Lib\site-packages\anvil\server.py”, line 421, in call
return _do_call(args, kwargs, fn_name=fn_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “H:\My Drive\projects\jan_svenda\ceo_cfo_database\scripts.venv\Lib\site-packages\anvil\server.py”, line 411, in _do_call
return _threaded_server.do_call(args, kwargs, fn_name=fn_name, live_object=live_object)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “H:\My Drive\projects\jan_svenda\ceo_cfo_database\scripts.venv\Lib\site-packages\anvil_threaded_server.py”, line 505, in do_call
raise error_from_server
anvil._server.AnvilWrappedError: anvil.server.call() expects atleast 1 argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “H:\My Drive\projects\jan_svenda\ceo_cfo_database\scripts\get_form3_data.py”, line 16, in
main()
File “H:\My Drive\projects\jan_svenda\ceo_cfo_database\scripts\get_form3_data.py”, line 9, in main
execs = anvil.server.call(‘api_executive_read’, cik=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “H:\My Drive\projects\jan_svenda\ceo_cfo_database\scripts.venv\Lib\site-packages\anvil\server.py”, line 424, in call
raise _server._deserialise_exception(e.error_obj)
anvil._server.AnvilWrappedError: anvil.server.call() expects atleast 1 argument

Is it possible that you have more than one definition of the affected server functions? E.g., in server modules, or in dependencies, or in other, still-running Uplink instances?

1 Like

I’ve been bitten by that very bug many times: Show list of registered functions in account

EDIT
If that is the case, changing the name of the callable should prevent any confusion with other versions.

1 Like

Good idea!

Technically, allowing multiple definitions is a feature, allowing work to be distributed among multiple running instances of an Uplink program, and allowing fallback to a server-side routine, when no corresponding Uplink program is available. But without any tracking feature, as you requested, it is also a footbrick.

(I define “footbrick” as less injurious than a footgun.)

1 Like

Thank you both! There should be no running uplink instances at the moment.

I’ve also tried changing the name of the callable, and it did not help. What is really strange, however, is that when I ran the following, I got the same error even though there’s no function defined with that name:

import anvil.server
import anvil.users
import pandas as pd

anvil.server.connect("...")
anvil.users.login_with_email("...", "...")

data = anvil.server.call('aaa')
print(data)

If i call a non existing function, I get a different error:
image

1 Like

I think something is going on. Without changing any code all the sudden my uplink is disconnected and I can’t get it working again in the editor. The client_uplink code says it’s connected but this error leads me to believe something is broken. Not encouraging.

anvil.server.UplinkDisconnectedError: The uplink server for “function_name” has been disconnected

1 Like

Today, I ran a server function via uplink on a different project and it worked fine.

The app id where I am experiencing this issue is SXVBLVXSTNADNIXX. Could someone please look into it?

I also tried changing the server uplink key to the different app I mentioned in the post above. When I run the script, I get the anvil._server.NoServerFunctionError: No server function matching... error. When I switch it back to the correct key, I get the anvil._server.AnvilWrappedError: anvil.server.call() expects atleast 1 argument error.

@acerrato → Did you manage to resolve your issue?

I still cannot get my code working. :confused:

As I mentioned, this issue is specific to one of my apps. Uplink works fine when I connect to the other ones.

Could anyone from Anvil please take a look? I am not sure how to tag them.

Hi @lojkasek.david,

I had a look and I can’t see anything obvious. Does the function work as expected when you call it from within the app? I appreciate that error is not very helpful, but it’s probably catching some other exception within the code.

Oh, this is awkward!

Hi Brooke, thanks! That was a good idea—the problem was I wrapped the function with @anvil.server.call() instead of @anvil.server.callable(). :upside_down_face:

In this case I apologize to everyone!