Ver Fonte

Fix event handler formatting (#174)

Nikhil Rao há 2 anos atrás
pai
commit
e32ffb6aed
1 ficheiros alterados com 6 adições e 1 exclusões
  1. 6 1
      pynecone/utils.py

+ 6 - 1
pynecone/utils.py

@@ -836,7 +836,12 @@ def format_event_handler(handler: EventHandler) -> str:
     state_name, name = parts[-2:]
 
     # Construct the full event handler name.
-    state = vars(sys.modules[handler.fn.__module__])[state_name]
+    try:
+        # Try to get the state from the module.
+        state = vars(sys.modules[handler.fn.__module__])[state_name]
+    except:
+        # If the state isn't in the module, just return the function name.
+        return handler.fn.__qualname__
     return ".".join([state.get_full_name(), name])