Local variable referenced before assignment

My app is connected to a Pico W, and I’m trying to use the following code to send the “ftx_dspsave1” command. I have several other similar server calls in my code that work as intended, but this one seems to cause the “Error: local variable referenced before assignment”

This seems very similar to a bug discussed here: [Fixed] UnboundLocalError: local variable 'anvil' referenced before assignment

from anvil import *
import anvil.facebook.auth
import anvil.server
import anvil.google.auth, anvil.google.drive
from anvil.google.drive import app_files
import anvil.users
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables

class Dose(DoseTemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)
    #TODO: put items in designer

  def button_1_click(self, **event_args):
    """This method is called when the button is clicked"""
    anvil.server.call_s("ftx_dspsave1")
    pass


Thanks in advance

Welcome to the Forum!

I see nothing in this code that creates or references any local variables.

Do you have any Data Bindings in your visual components? The references might be occurring there.

Thanks for the reply. You can tell why I’m confused- there are no variables I’m trying to reference. I can replace anvil.server.call_s(“ftx_dspsave1”) with several other calls that work just fine, but for some reason this call (and anvil.server.call_s(“ftx_dspsave2”) cause the variable reference error.

I have no data bindings anywhere in my app. I’m still learning Anvil and haven’t found a use for data bindings yet… mainly because I don’t know how they work.

Can you provide more details about the error?
At what line does it happen?
Can you show the traceback?

Yes, sorry, I should have included that the first time. Knew I forgot something…

Error: local variable referenced before assignment
at Setup, line 26

Line 26:

    anvil.server.call_s("ftx_dspsave1")

Can you show the full traceback? Seeing what call what may help.

Have you tried changing the name of ftx_dspsave2, both the function definition and where it is called?

Or moving it to another module?

Or commenting out all its code and immediately returning?

Thanks for the ideas - I haven’t solved the problem but I am now confident it’s not in the code on Anvil.

I commented out everything run by the command on the Pico and the command worked without error. I’ll have to dig into that code to find the culprit. I was thrown off by the error traceback only appearing on the Anvil side.

Thanks again for the help!