Using Uplink to transfer data between two Anvil App's

I need to send old data frequently from a working Anvil App to an Archive Anvil App.

I used “Up link” , considering a server module in the Archive App as a Remote code as follows :

import anvil.users
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables

import anvil.server

anvil.server.connect(“server_G5AUNNZV5B7Q5QQOIJLSNYLA-QWYJ7DR6ASLTXWTY”)

@anvil.server.callable
def eConsoltoUplink_AddResidence(Hosppital,Country,City,Patient,PDepartment,Room,Bed,ResidenceFrom_DT,ResidenceTo_DT):
PricingRow = app_tables.pricing.get(Country=Country)
CostRate = PricingRow[‘CostRate’]
Days = (ResidenceTo_DT - ResidenceFrom_DT).days
Cost = CostRate * Days
app_tables.residences.add_row(Hosppital=Hosppital,Country=Country,City=City,Patient=Patient,PDepartment=PDepartment,ResidenceFrom_DT=ResidenceFrom_DT,ResidenceTo_DT=ResidenceTo_DT, Room=Room, Bed=Bed,Days=Days,CostRate=CostRate,Cost=Cost)

anvil.server.wait_forever()

but when I call the server module of the Archive App From the Client side of the Working App, I have got this error :
anvil.server.NoServerFunctionError: No server function matching “eConsoltoUplink_AddResidence” has been registered

Thank you for help

To resolve this, make sure you define the function before calling anvil.server.connect(). The server must be fully aware of all registered functions at the time the connection is established, otherwise they won’t be available for remote calls.

Side note: If your goal is to share data between two Anvil apps, the most robust approach is to share the data tables themselves by granting both apps access to the same Data Tables. This way, each app can interact directly with the shared data. This is generally better than transferring data via Uplink unless you need to selectively expose only part of the data for security, isolation, or other architectural reasons.

Thank you for help, but for “make sure you define the function before calling anvil.server.connect()” . is there any document for this.

Anvil doesn’t document elementary Python features and behavior. It leaves that to other sources. But in a nutshell, when Python loads a module, it executes the module’s code from top to bottom.

This includes the def statement. When the def executes, it defines the function, and binds that definition to the function name.

As the code above is written, at run-time, the anvil.server.connect executes before the def, so at that time, the def hasn’t happened yet, so the function does not yet exist.

To get the def statement to execute before the anvil.server.connect does, you place it physically before the anvil.server.connect, i.e., in the lines above your anvil.server.connect call.

2 Likes