Common errors in the Anvil Editor
This page explains common errors and warnings you may see when you run an app in the Anvil Editor and how to fix them.
Server callable defined in client code
The error @anvil.server.callable can only be used in server code appears when you use the @anvil.server.callable decorator in a Form or client Module.
The decorator makes a function in a Server Module available to client code. If the function should run only in client code, remove the decorator and call the function normally.
If the function needs to run on the server, move it into a Server Module:
import anvil.server
@anvil.server.callable
def get_message():
return "Hello from the server"Then call the function from your Form or client Module:
message = anvil.server.call('get_message')Read more about calling server functions from client code and the difference between client and server code.
Service not added
This error appears when your code uses an Anvil service that has not been added to your app. For example, code that calls anvil.users.get_user() needs the Users Service.
To add the service:
- Click the blue plus button
in the Sidebar Menu. - Select the service named in the error.
Anvil will add the service to the Sidebar Menu and add the necessary imports to your code.
Read more about adding services and integrations from the Sidebar Menu.
Missing or invalid event handler
Warnings such as No method "save_click" in form Form1 or "save_click" in form Form1 is not a method mean that an event is bound to a name that is missing or is not a function. The component will not run that handler when the event occurs.
If the event was configured in the Properties Panel:
- Select the component in Design view.
- Find the named event in the Properties Panel.
- Correct the handler name, or clear it if the event no longer needs a handler.
If you deleted the method by mistake, restore it in the same Form. For example:
def save_click(self, **event_args):
# Save the user's changes here.
passIf the name exists but refers to a component or other value, choose a method instead. Check for a component that hides a method.
Read more about setting event handlers, including using the @handle decorator.
Component name hides a method or attribute
The warning has a method or attribute 'save' and a component called 'save' means that a component has replaced a Form method or attribute with the same name. For example, a Button named save makes self.save refer to that Button, so you can no longer call a method named save as self.save().
Select the component in Design view and give it a different name in the Properties Panel, such as save_button. Update code that refers to the component. Alternatively, rename your method or attribute and update its references and event bindings.
Read more about accessing components from Form code.
Popup options ignored
The warning options must be passed as keyword arguments appears when you pass extra positional arguments to alert(), confirm() or Notification(). Only the first argument supplies the content or message; the extra positional arguments are ignored.
Pass options such as title, buttons and timeout by name. For example, alert("Saved", "Details") ignores "Details". Use title="Details" instead:
alert("Saved", title="Details")
confirm("Delete this row?", title="Confirm deletion")
Notification("Saved", title="Details", timeout=3).show()Read more about alerts and notifications.
RichText formatting failed
The warning Could not format RichText slot value means that a value in a RichText component’s data does not work with the slot’s format string. The slot is left blank.
For example, {price:.2f} expects a number. A string or None cannot be formatted this way. Supply a number, change the slot’s format, or handle missing values before displaying them.
For values that can be missing, you can format them in code and use a slot without a numeric format:
price = None
self.rich_text_1.content = "Price: {price}"
self.rich_text_1.data = {
"price": "Not available" if price is None else f"{price:.2f}"
}Read more about RichText slots and formatting.
Deprecated jQuery features
The warning This application uses deprecated jQuery 2.2 features means that JavaScript in your app, or a library it loads, uses an older jQuery feature. The Error: part of the warning identifies the feature.
To find and update the affected code:
- Read the feature named after
Error:in the warning. - Find the JavaScript that calls it. This may be your own code or a third-party library. Your browser’s developer tools can help you inspect loaded scripts.
- If it is your code, replace that call with a supported alternative. If it comes from a library, update the library to a compatible version or contact its maintainer. Then test the interaction again.
For example, replace $(element).size() with $(element).length.
See the jQuery 3 upgrade guide for changes and replacements. Read more about using JavaScript in Anvil.
Moment localisation warnings
Warnings such as moment.locale is deprecated: Anvil no longer includes Moment.js mean that your app, or a library it loads, still calls a Moment.js API.
Update DatePicker localisation
Older DatePicker localisation workarounds are still supported, but produce a warning. Use Python’s locale module instead. For example, replace moment.locale("de") with:
import locale
locale.setlocale(locale.LC_TIME, "de_DE")In a Form, put this call before the class definition so it runs before the DatePickers are created. This also affects other locale-sensitive date formatting, such as strftime(). The same now applies when you use older Moment locale calls.
After updating your code, remove any scripts you added only for Moment locales from JavaScript Dependencies, formerly Native Libraries. See Localising Dates and Numbers for more examples and browser support.
Replace other Moment calls
Use Python’s datetime module for date calculations and formatting. For example, replace moment().format("YYYY-MM-DD") with:
from datetime import date
text = date.today().strftime("%Y-%m-%d")If a third-party library requires Moment.js, update the library or load Moment.js through JavaScript Dependencies.
Plotly Mapbox warnings
You may see either of these warnings when a Plot component uses older map code:
Warning: This plot uses deprecated Mapbox names.Warning: Plotly ignores Mapbox access tokens.
Each warning appears once per app run. Anvil translates the old map names so existing code can still render. Update your code as described below to remove the warnings.
Update the map names
Replace the old names in your Python code:
| Old name | New name |
|---|---|
go.Scattermapbox |
go.Scattermap |
go.Choroplethmapbox |
go.Choroplethmap |
go.Densitymapbox |
go.Densitymap |
layout.mapbox |
layout.map |
If you create maps in server code, install plotly>=5.24.0 in your server Python packages before using the new names.
Remove Mapbox tokens and choose a background
Remove accesstoken from the map layout and mapboxAccessToken from the Plot configuration. Plotly no longer uses these settings. Built-in map styles, including carto-positron, do not need a token:
import plotly.graph_objects as go
self.plot_1.data = go.Scattermap(lat=[40.7128], lon=[-74.0060], mode="markers")
self.plot_1.layout.map = dict(
style="carto-positron",
center=dict(lat=40.7128, lon=-74.0060),
zoom=10
)Built-in styles such as light and dark still work, but their appearance may change. Backgrounds selected with a mapbox:// URL or the old stamen-terrain, stamen-toner and stamen-watercolor names are no longer supported. To use the background shown above, change your map’s style to "carto-positron".
If you need to keep a custom background, obtain a MapLibre-compatible style URL from your map provider. Follow the provider’s instructions for supplying any required key in its HTTPS URLs; Plotly’s old Mapbox token settings will not supply it.
These warnings identify old map names and token settings. They do not detect whether a map background loaded successfully. See Plotly’s map-layer documentation for supported backgrounds and custom map layers.
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.